# Centering column in matrix equations

I'm looking for a way to centre-align the centre column (\xrightarrows) in this construction.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{alignat}[2]
\begin{bmatrix*}[r]
2 & 2 & \vline & 3 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \xrightarrow{-R_2 \to R_1} && \begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} \\
\begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \xrightarrow{3 R_1} && \begin{bmatrix*}[r]
3 & 15 & \vline & \mathllap{-}1 \\
1 & -3 & \vline & 2
\end{bmatrix*}
\end{alignat}
\end{document}


Previous answers I've seen have used:

• is insetead of \end{bmatrix*} & \xrightarrow{-R_2 \to R_1} && \begin{bmatrix*}[r] acepptable to you \end{bmatrix*} & \xrightarrow{-R_2 \to R_1} \begin{bmatrix*}[r]? Jul 17, 2017 at 18:48
• No, I want the \xrightarrows to be centre-aligned, not left-aligned. Jul 18, 2017 at 0:21

The alignat environment works just fine here. What made you believe it turns the centre column in textmode? Note the starred versions of the matrix environmùents require mathtools. I took the opportunity to align the right brackets of the righmots matrices, using the \mathllap command defined by this package:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
\begin{bmatrix*}[r]
2 & 2 & \vline & 3 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \xrightarrow{-R_2 \to R_1} && \begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} \\[1ex]
\begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \xrightarrow{-R_2 \to R_1} && \begin{bmatrix*}[r]
0 & 8 & \vline & \mathllap{-}1 \\
1 & -3 & \vline & 2
\end{bmatrix*}
\end{alignat*}

\end{document}


To centre the \rightarrows in their column, we can use the eqparbox package. I defines a \eqmathbox command, which types its contents in math mode and uss a system of tags. All boxes sharing the same tag have the width of the wides of their contents, which is centred in its box:

\documentclass{article}
\usepackage{mathtools}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$\displaystyle#2$}}

\begin{document}

\begin{alignat*}{2}
\begin{bmatrix*}[r]
2 & 2 & \vline & 3 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \eqmathbox{\xrightarrow{-R₂ + R_1\to R₁}} && \begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} \\[1ex]
\begin{bmatrix*}[r]
1 & 5 & \vline & 1 \\
1 & -3 & \vline & 2
\end{bmatrix*} & \eqmathbox{\xrightarrow{-R₂ \to R₁}} && \begin{bmatrix*}[r]
0 & 8 & \vline & \mathllap{-}1 \\
1 & -3 & \vline & 2
\end{bmatrix*}
\end{alignat*}

\end{document}


• I didn't say that the alignat environment turns the centre column into text mode, but the referenced answer does turn it into text mode. In your answer the \xrightarrow column is left-aligned, not centred. I suspect my example doesn't show this clearly, I'll edit it. Jul 18, 2017 at 0:18
• @user164587: I se what you mean: the \xrightarrows look centred because they have the same width. I have a solution with eqparbox . Please take a look at my updated answer. Jul 18, 2017 at 1:58