[Tex/LaTex] Arrows for Matrix Row Operations

matrices

How do you create the arrows indicating matrix row operations in a non-array environment? I'm trying to have the same output as: row arrow

I currently have

\item
        \[
        \begin{bmatrix}
            1 & 7 & 3 & -4 \\
            0 & 1 & -1 & 3 \\
            0 & 0 & 0 & 1 \\
            0 & 0 & 1 & -2
        \end{bmatrix}
        \begin{bmatrix}
            1 & 7 & 3 & -4 \\
            0 & 1 & -1 & 3 \\
            0 & 0 & 1 & -2 \\
            0 & 0 & 0 & 1
        \end{bmatrix} 
        \]

and I want to place the arrow in between.

Best Answer

You can use \xrightarrow, with some help in order to equalize the widths.

\documentclass{article}
\usepackage{amsmath,mathtools}

\newenvironment{sysmatrix}[1]
 {\left(\begin{array}{@{}#1@{}}}
 {\end{array}\right)}
\newcommand{\ro}[1]{%
  \xrightarrow{\mathmakebox[\rowidth]{#1}}%
}
\newlength{\rowidth}% row operation width
\AtBeginDocument{\setlength{\rowidth}{3em}}

\begin{document}

\begin{alignat*}{2}
\begin{sysmatrix}{rrr|r}
 1 &  2 & 0 & 0 \\
-1 &  1 & 2 & 0 \\
 1 &  0 & 1 & 5 \\
 0 & -2 & 1 & 4
\end{sysmatrix}
&\!\begin{aligned}
&\ro{r_2+r_1}\\
&\ro{r_3-r_1}
\end{aligned}
\begin{sysmatrix}{rrr|r}
1 &  2 & 0 & 0 \\
0 &  3 & 2 & 0 \\
0 & -2 & 1 & 5 \\
0 & -2 & 1 & 4
\end{sysmatrix}
&&\ro{(1/3)r_2}
\begin{sysmatrix}{rrr|r}
1 &  2 &   0 & 0 \\
0 &  1 & 2/3 & 0 \\
0 & -2 &   1 & 5 \\
0 & -2 &   1 & 4
\end{sysmatrix}
\\
&\!\begin{aligned}
&\ro{r_3+2r_2}\\
&\ro{r_4+2r_2}
\end{aligned}
\begin{sysmatrix}{rrr|r}
1 &  2 &   0 & 0 \\
0 &  1 & 2/3 & 0 \\
0 &  0 & 7/3 & 5 \\
0 &  0 & 7/3 & 4
\end{sysmatrix}
&&\ro{(3/7)r_3}
\begin{sysmatrix}{rrr|r}
1 &  2 &   0 & 0 \\
0 &  1 & 2/3 & 0 \\
0 &  0 &   1 & 15/7 \\
0 &  0 & 7/3 & 4
\end{sysmatrix}
\end{alignat*}

\end{document}

enter image description here