Formatting arrows between rows of corresponding matrices

One way to do this is implemented in the (free, in both senses!) online linear algebra textbook Linear Algebra by Jim Hefferon. It's written in LaTeX and is open-source so one can download the book and its attendant style files. One of them, called linalgjh.sty is about typesetting common linear algebra stuff such as augmented matrices and row reductions and the like. The code for the row reductions is:

%--------grstep
% For denoting a Gauss' reduction step.
% Use as: \grstep{\rho_1+\rho_3} or \grstep[2\rho_5 \\ 3\rho_6]{\rho_1+\rho_3}
\newcommand{\grstep}[2][\relax]{%
   \ensuremath{\mathrel{
       {\mathop{\longrightarrow}\limits^{#2\mathstrut}_{
                                     \begin{subarray}{l} #1 \end{subarray}}}}}}
\newcommand{\swap}{\leftrightarrow}

and is used as:

\documentclass{article}
\usepackage{amsmath}
\usepackage{linalgjh}
\thispagestyle{empty}
\begin{document}

    \[
    \begin{bmatrix}
    -1&2&-1&-2\\%
    2&-3&4&1\\%
    2&3&1&-2
    \end{bmatrix}
    %
    \grstep[R_3 + 2 R_1]{R_2 + 2 R_1}
    %
    \begin{bmatrix}
    -1&2&-1&-2\\%
    0&1&2&-3\\%
    0&7&-1&-6
    \end{bmatrix}
    \]
\end{document}

This produces:

grstep example

This isn't quite the same as in the question, I freely admit, so may not be a Good Answer as far as the original questioner is concerned. However, someone else looking at this question might not be so bothered about the arrows being aligned on the rows and so this might suffice. Also, the linalgjh package is worth mentioning more than once, as is the text book that it was developed to produce.

That style file has several other useful linear algebra macros that may be useful (I previously mentioned it in answer to this question).


I can't offer anything other than making your arrows into a simple macro to make it easier to type. Something like

\newcommand\arrows[3]{
        \begin{matrix}[c]
        \ifx\relax#1\relax\else \xrightarrow{#1}\fi\\
        \ifx\relax#2\relax\else \xrightarrow{#2}\fi\\
        \ifx\relax#3\relax\else \xrightarrow{#3}\fi
        \end{matrix}
}

You'd use it like \arrows{}{R_2-2R_1}{R_3+R_1}

Maybe it'd be better to explicitly pass in the number of rows, like this.

\newcount\arrowcount
\newcommand\arrows[1]{
        \global\arrowcount#1
        \ifnum\arrowcount>0
                \begin{matrix}[c]
                \expandafter\nextarrow
        \fi
}

\newcommand\nextarrow[1]{
        \global\advance\arrowcount-1
        \ifx\relax#1\relax\else \xrightarrow{#1}\fi
        \ifnum\arrowcount=0
                \end{matrix}
        \else
                \\
                \expandafter\nextarrow
        \fi
}

You'd use it like \arrows3{}{}{R_2+R_3}. It seems to work for your example.


as i see it, the problem is that the rows of the matrices are too close together. if they were farther apart, the arrows should be able to align.

a fix for this is provided by the array package (from the latex tool set). with this, you can specify (for example)

\setlength{\extrarowheight}{3pt}

and that will space out the rows. this should be done outside the affected display, and will continue in effect thereafter, so if you don't want it everywhere, you either need to turn it off after the affected display(s), or limit its scope by appropriate grouping.