# Side by Side matrices

How can I get matrices that are side by side? Currently I have the following:

$\begin{pmatrix}[ccc|c] 1&2&0&0\\ -1&1&2&0\\ 1&0&1&5\\ 0&-2&1&4 \end{pmatrix}$
$\begin{pmatrix}[ccc|c] 1&2&0&0\\ 0&3&2&0\\ 0&-2&1&5\\ 0&-2&1&4 \end{pmatrix}$


What I want is the matrices to go across the paper with row equivalence signs on them (I am showing a reduced echelon form matrix)

-

Are you looking for \sim ("row equivalence sign")? (Also: *matrix doesn't take an optional parameter.)

## Code

\documentclass{article}
\begin{document}
$\left(\begin{array}{@{}ccc|c@{}} 1 & 2 & 0 & 0 \\ -1 & 1 & 2 & 0 \\ 1 & 0 & 1 & 5 \\ 0 & -2 & 1 & 4 \end{array}\right) \sim \left(\begin{array}{@{}ccc|c@{}} 1 & 2 & 0 & 0 \\ 0 & 3 & 2 & 0 \\ 0 & -2 & 1 & 5 \\ 0 & -2 & 1 & 4 \end{array}\right)$
\end{document}


## Improvement

If you use those matrices more than once you can define a new environment that does this for you:

\documentclass{article}
\newenvironment{rowequmat}[1]{\left(\array{@{}#1@{}}}{\endarray\right)}
\begin{document}
$\begin{rowequmat}{ccc|c} 1 & 2 & 0 & 0 \\ -1 & 1 & 2 & 0 \\ 1 & 0 & 1 & 5 \\ 0 & -2 & 1 & 4 \end{rowequmat} \sim \begin{rowequmat}{ccc|c} 1 & 2 & 0 & 0 \\ 0 & 3 & 2 & 0 \\ 0 & -2 & 1 & 5 \\ 0 & -2 & 1 & 4 \end{rowequmat}$
\end{document}

-

Don't use two separate environments for displyed math. As Mico has suggested in his answer, it's better to use array environments.

In the following example I defined two environments, one for the matrices and another one for the elementary row operations; I also defined two commands for two of the row operations. Using an alignat environment you can align the matrices and their operations:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\newenvironment{redmatrix}
{\left(\array{@{}rrr|c@{}}}
{\endarray\right)}
\newenvironment{ropmatrix}
{\array{@{}c@{}}}
{\endarray}
\newcommand\opone[2]{\xrightarrow{(#1)\times r_#2}}
\newcommand\optwo[3]{\xrightarrow{r_#1{}+{} #2r_#3}}

\begin{document}
\begin{alignat*}{5}
&
\begin{redmatrix}
1&2&0&0\\
-1&1&2&0\\
1&0&1&5\\
0&-2&1&4
\end{redmatrix}
&
\begin{ropmatrix}
\optwo{1}{}{2}
\end{ropmatrix}
&
\begin{redmatrix}
1&2&0&0\\
0&3&2&0\\
0&-2&1&5\\
0&-2&1&4
\end{redmatrix}
&
\begin{ropmatrix}
\opone{1/3}{2}
\end{ropmatrix}
&
\begin{redmatrix}
1&2&0&0\\
0&1&2/3&0\\
0&-2&1&5\\
0&-2&1&4
\end{redmatrix}\\
&&
\begin{ropmatrix}
\optwo{3}{2}{2}\\
\optwo{4}{2}{2}\\
\end{ropmatrix}
&
\begin{redmatrix}
1&2&0&0\\
0&1&2/3&0\\
0&0&7/3&5\\
0&0&7/3&4
\end{redmatrix}
&
\begin{ropmatrix}
\opone{3/7}{3}
\end{ropmatrix}
&
\begin{redmatrix}
1&2&0&0\\
0&1&2/3&0\\
0&0&1&15/7\\
0&0&7/3&4
\end{redmatrix}
\end{alignat*}

\end{document}


-

I suggest you use array instead of pmatrix environments, as arrays give you more flexibility with regard to the positioning of the elements of a column, and also let you insert vertical bars. Separately, don't specify two separate display math environments, but only one. Here's an MWE:

\documentclass{article}
\usepackage{array}
\begin{document}
$\left(\begin{array}{@{}rrr|c@{}} 1&2&0&0\\ -1&1&2&0\\ 1&0&1&5\\ 0&-2&1&4 \end{array}\right) \quad \left(\begin{array}{@{}rrr|c@{}} 1&2&0&0\\ 0&3&2&0\\ 0&-2&1&5\\ 0&-2&1&4 \end{array}\right)$
\end{document}


-
\documentclass{article}
\usepackage{array}
\begin{document}

$\left(\begin{array}{cccccc}1&-2&0&2&0&1\\0&0&1&5&0&-3\\0&0&0&0&1&6\\0&0&0&0&0&0\end{array}\right|\left.\begin{array}{c}1\\-1\\1\\0\end{array}\right)$

\end{document}

-
Thanks for your participation, Eva, but the code you provided (without any sort of explanation) does not produce the output desired by the person who asked the question. – Clément Feb 13 at 4:10