Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
    
Welcome to TeX.SX! –  Adam Liter Jan 22 at 2:44
    
Thanks @Adam. :) –  Ra1nWarden Jan 22 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 at 3:26
add comment

2 Answers

up vote 11 down vote accepted

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.

share|improve this answer
2  
For reference: Why is \[ … \] preferable to $$ … $$? –  Adam Liter Jan 22 at 5:51
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.