8

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: enter image description here

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

2 Answers2

11

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.

enter image description here

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

Gonzalo Medina
  • 505,128
2

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}

enter image description here