[texhax] Typesetting row operations in matrices

Matthew Leingang leingang at math.harvard.edu
Fri Mar 24 21:15:52 CET 2006

Hello list,

I'm preparing notes for a linear algebra class in which we do a lot of
Gaussian Elimination of matrices.  Every time I do this I fret about the
best way to indicate row operations in TeX.

When I'm talking at the board and I want to say "we're going to transpose
row 1 and row 3 of this matrix", I draw a double-ended arrow on the
right-hand side of the matrix, pointing to the first and third row.  If I
want to represent the row operation "add -2 times the first row to the
second row", I draw an arrow from the right side of row 1 to the right side
of row 2, decorated with a "-2".

I'd like to get the same thing in my TeX-ed notes.  The only way I know how
to do curved arrows is in Xy-Pic [Yes, I'll post over at their ML, but it's
so low volume I'm worried that maybe it's gone out of style].  I can do
something like

\xymatrix{1 & 1 & 1 & 1 & 0 \\ 0 & 1 & -1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0

Which is pretty close.  You can set the row and column separation parameters
so the spacing is just like it is in LaTeX matrices.

But usually matrices are delimited by something, like square brackets or
parentheses.  I want the numbers part of the matrix to go inside the
delimiters but the curved arrows to go outside the delimiter on the RHS.
Putting \left[...\right] about the above, predictably, puts the delimiter
outside the arrows (also, unpredictably, extends the delimiter about 2/3
higher than the visible natural height of the matrix).

Right now this is the closest I can get:



1 & 1 & 1 & 1 & 0 \\ 0 & 1 & -1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0


I've also tried some hacks like using a regular matrix environment with an
xymatrix next to it, containing no visible entries and just the arrows.  But
the regular matrix's bottom gets vertically aligned with the xymatrix's
middle.  The only way I know how to fix that is to move up the xmymatrix,
creating monstrosities like

\left[\begin{matrix}1 & 1 & 1 & 1 & 0 \\ 2 & 0 & 4 & 2 & 0 \\ 1 & 1 & 1 & 3
& 0 \end{matrix}\right]
{\mathstrut} \ar@/^3ex/[d]_{-2} \ar@/^4ex/[dd]^{-3} \\ {\mathstrut}\\
{\mathstrut} }}}

This does "work" but if the matrix environment changes the xymatrix kludge
matrix has to change, too.

At which point I start thinking, "there's gotta be a better way."   Does
anybody know of an existing solution?  I'd be satisfied with my hack if I
could get my two matrices to line up.  Should I be using a different


Matthew Leingang
Preceptor in Mathematics
Harvard University

URL: http://www.math.harvard.edu/~leingang/
vCard: http://www.math.harvard.edu/~leingang/vCard.vcf

More information about the texhax mailing list