How to add equations on top of arrows?

I have the following matrix:

$$\left[ \begin{array}{ccc|c} -4&2&-2&10 \\ 1&0&1&-3 \\ 3&-1&1&-8 \end{array} \right] \sim$$


I want to have something like this:

How shall I add equations on top of the ~ and make these align? Thanks!

-
Welcome to TeX.SX! – Adam Liter Jan 22 '14 at 2:44
Thanks @Adam. :) – Ra1nWarden Jan 22 '14 at 2:47
I made an edit to my answer, simplifying the code; the new version might be of interest for you. – Gonzalo Medina Jan 22 '14 at 3:26

With the help of \overset and a \parbox, you can achieve what you want:

\documentclass{article}
\usepackage{amsmath}

\newlength\TextWd
\setlength\TextWd{2.5cm}

\newcommand\Textsim[1]{%
\overset{\parbox[b]{2.5cm}{%
\centering\scriptsize#1}}{\sim}
}

\begin{document}

\begin{align*}
\begin{bmatrix}
-4&2&-2&10 \\
1&0&1&-3 \\
3&-1&1&-8
\end{bmatrix}
&\Textsim{$R_{1}\Leftrightarrow R_2$ \\ \mbox{} }
\begin{bmatrix}
-4&2&-2&10 \\
1&0&1&-3 \\
3&-1&1&-8
\end{bmatrix} \\
&\Textsim{$-2R_{1}+R_2\Rightarrow R_2$ \\ $R_1+ R_3\Rightarrow R_3$ }
\begin{bmatrix}
-4&2&-2&10 \\
1&0&1&-3 \\
3&-1&1&-8
\end{bmatrix} \\
&\Textsim{$2R_{2}+R_3\Rightarrow R_3$ \\ \mbox{}}
\begin{bmatrix}
-4&2&-2&10 \\
1&0&1&-3 \\
3&-1&1&-8
\end{bmatrix}
\end{align*}

\end{document}


Using the length \TextWd you can control the width of the box.

Notice that $$...$$ is old TeX syntax which should be replaced with $...$ in LaTeX documents. I also built the matrices using bmatrix from amsmath.

-
For reference: Why is $…$ preferable to $$…$$? – Adam Liter Jan 22 '14 at 5:51

Here is a solution using stacks. The 9pt stackgap is the distance between baselines of the stacked material above the \sim, while the 10pt optional argument to \stackunder is the gap between successive matrices. The 1in \makebox is the width allotted for the center \sim stacks.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\stackMath
\setstackgap{L}{9pt}
\usepackage{amsmath}
\begin{document}
\renewcommand\stackalignment{r} \stackunder[10pt]{ \stackunder[10pt]{ \renewcommand\stackalignment{c} \begin{bmatrix} -4&2&-2&10 \\ 1&0&1&-3 \\ 3&-1&1&-8 \end{bmatrix} \makebox[1in]{\Longstack{\scriptstyle R_{1}\Leftrightarrow R_2\\\sim}} \begin{bmatrix} -4&2&-2&10 \\ 1&0&1&-3 \\ 3&-1&1&-8 \end{bmatrix} }{ \renewcommand\stackalignment{c} \makebox[1in]{\Longstack{ \scriptstyle -2R_{1}+R_2\Rightarrow R_2 \\ \scriptstyle R_1+ R_3\Rightarrow R_3\\\sim}} \begin{bmatrix} -4&2&-2&10 \\ 1&0&1&-3 \\ 3&-1&1&-8 \end{bmatrix} }}{ \renewcommand\stackalignment{c} \makebox[1in]{\Longstack{ \scriptstyle 2R_{2}+R_3\Rightarrow R_3\\\sim}} \begin{bmatrix} -4&2&-2&10 \\ 1&0&1&-3 \\ 3&-1&1&-8 \end{bmatrix} }
\end{document}


-