# Reducing horizontal space in math mode align

The following code aligns everything just the way I want -- and I can be much too picky -- except that the horizontal space to the last column is too wide. How can I make it narrower?

\begin{align*}
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
2 & 5 &  -8 & 4
\end{pmatrix*}
&\sim
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\\
\leftarrow -2r_1 + r_2
\end{matrix*} \\
&\sim
\begin{pmatrix*}[r]
1 & 0 & 1 & -3 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\leftarrow -2r_2 + r_1 \\
\\
\end{matrix*}
\end{align*}


You could use \begin{alignat*}{3} ... \end{alignat*} and replace the && %\qquad with & \quad:

## Code:

\documentclass[preview,border=2mm]{standalone}
\usepackage{mathtools}% <-- includes amsmath

\begin{document}
Using \verb|align*|
\begin{align*}
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
2 & 5 &  -8 & 4
\end{pmatrix*}
&\sim
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\\
\leftarrow -2r_1 + r_2
\end{matrix*} \\
&\sim
\begin{pmatrix*}[r]
1 & 0 & 1 & -3 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\leftarrow -2r_2 + r_1 \\
\\
\end{matrix*}
\end{align*}
Using \verb|alignat*|
\begin{alignat*}{2}
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
2 & 5 &  -8 & 4
\end{pmatrix*}
&\sim
\begin{pmatrix*}[r]
1 & 2 &  -3 & 1 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\\
\leftarrow -2r_1 + r_2
\end{matrix*} \\
&\sim
\begin{pmatrix*}[r]
1 & 0 & 1 & -3 \\
0 & 1 &  -2 &  2
\end{pmatrix*}
\begin{matrix*}[l]
\leftarrow -2r_2 + r_1 \\
\\
\end{matrix*}
\end{alignat*}
\end{document}


aligned allows several alignment points using the & symbol. If you need more space for the last column, use qquad or a similar hspace.

\documentclass[12pt,a4paper]{article}
\usepackage{mathtools}
\begin{document}

\begin{aligned} \begin{pmatrix*}[r] 1 & 2 & -3 & 1 \\ 2 & 5 & -8 & 4 \end{pmatrix*} &\sim \begin{pmatrix*}[r] 1 & 2 & -3 & 1 \\ 0 & 1 & -2 & 2 \end{pmatrix*} & \leftarrow -2r_1 + r_2 \\ &\sim \begin{pmatrix*}[r] 1 & 0 & 1 & -3 \\ 0 & 1 & -2 & 2 \end{pmatrix*} & \leftarrow -2r_2 + r_1 \end{aligned}

\end{document}