# How to make the matrices look constant throughout?

I'm trying to make the following matrices look constant throughout, that is not change their size. I'm having trouble with the third.

What do you suggest I use instead or maybe alter this?

First, we write this system using matrices.

$\left[ \begin{array}{ccc|c} 1 & 2 & 3 & 4\\ 7 & 5 & 3 & 1\\ -2 & -3 & -4 & -5\\ \end{array} \right]$

We preform $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} - 7\mathbf{R_{1}}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} + 2\mathbf{R_{1}}$

$\left[ \begin{array}{ccc|c} 1 & 2 & 3 & 4\\ 0 & -9 & -18 & -27\\ 0 & 1 & 2 & 3\\ \end{array} \right]$

Next we $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} \times -\frac{1}{9}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} - \mathbf{R_{2}}$, for final

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


• Is i.sstatic.net/Obw3r.png closer to what you want to achieve? Commented Jun 2, 2020 at 19:24
• Hi there, I'm sure you can guess what the problem is, the problem is that the minus signs you just so happen to have in the first two just so happens to be missing from the last, although really it just depends on the width of each column and the number of digits (and the size of the digits, 1 being thinner than, say, 7) will also have an effect which means that your first and second matrices aren't exactly the same size, but they happen to work out close enough. An ugly hack might be to add a \phantom{-} Commented Jun 2, 2020 at 19:25
• @Au101 I'm agree with you :-) Commented Jun 2, 2020 at 19:29
• A less hacky solution could be to specify the width of your column, e.g. (requires the array package) try \begin{array}{*{3}{>{\centering}p{1cm}}|>{\centering}p{1cm}} (adjust lengths to taste) Commented Jun 2, 2020 at 19:29

The package nicematrix can compute for you the width of the widest entry of all the matrices in a portion of your document and give that width to all the columns.

For that, you have to use the environment {NiceMatrixBlock} with the key auto-columns-width.

You need several compilations.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

First, we write this system using matrices.

\begin{NiceMatrixBlock}[auto-columns-width]
$\begin{bNiceArray}{rrr|r} 1 & 2 & 3 & 4\\ 7 & 5 & 3 & 1\\ -2 & -3 & -4 & -5\\ \end{bNiceArray}$
We preform $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} - 7\mathbf{R_{1}}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} + 2\mathbf{R_{1}}$
$\begin{bNiceArray}{rrr|r} 1 & 2 & 3 & 4\\ 0 & -9 & -18 & -27\\ 0 & 1 & 2 & 3\\ \end{bNiceArray}$
Next we $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} \times -\frac{1}{9}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} - \mathbf{R_{2}}$, for final
$\begin{bNiceArray}{rrr|r} 1 & 2 & 3 & 4\\ 0 & 1 & 2 & 3\\ 0 & 0 & 0 & 0\\ \end{bNiceArray}$
\end{NiceMatrixBlock}
\end{document}


nicematrix allows you to set the column width.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
First, we write this system using matrices.
$\begin{bNiceArray}[columns-width = 2em]{RRR|R} 1 & 2 & 3 & 4\\ 7 & 5 & 3 & 1\\ -2 & -3 & -4 & -5\\ \end{bNiceArray}$
We preform $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} - 7\mathbf{R_{1}}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} + 2\mathbf{R_{1}}$
$\begin{bNiceArray}[columns-width = 2em]{RRR|R} 1 & 2 & 3 & 4\\ 0 & -9 & -18 & -27\\ 0 & 1 & 2 & 3\\ \end{bNiceArray}$
Next we $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} \times -\frac{1}{9}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} - \mathbf{R_{2}}$, for final
$\begin{bNiceArray}[columns-width = 2em]{RRR|R} 1 & 2 & 3 & 4\\ 0 & 1 & 2 & 3\\ 0 & 0 & 0 & 0\\ \end{bNiceArray}$
\end{document}


You could also measure the widest entry and use its width.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\setbox0\hbox{$-27$}%
\edef\mywd{\the\wd0}%
First, we write this system using matrices.
$\begin{bNiceArray}[columns-width=\mywd]{RRR|R} 1 & 2 & 3 & 4\\ 7 & 5 & 3 & 1\\ -2 & -3 & -4 & -5\\ \end{bNiceArray}$
We preform $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} - 7\mathbf{R_{1}}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} + 2\mathbf{R_{1}}$
$\begin{bNiceArray}[columns-width=\mywd]{RRR|R} 1 & 2 & 3 & 4\\ 0 & -9 & -18 & -27\\ 0 & 1 & 2 & 3\\ \end{bNiceArray}$
Next we $\mathbf{R_{2}} \rightarrow \mathbf{R_{2}} \times -\frac{1}{9}$ and $\mathbf{R_{3}} \rightarrow \mathbf{R_{3}} - \mathbf{R_{2}}$, for final
$\begin{bNiceArray}[columns-width=\mywd]{RRR|R} 1 & 2 & 3 & 4\\ 0 & 1 & 2 & 3\\ 0 & 0 & 0 & 0\\ \end{bNiceArray}$
\end{document}


Below I define gaussmat as a matrix-like construction/environment that sets a 3 x 3 Gaussian elimination matrix. The column entries are all the same, capturing its argument and passing it on to a measurement scheme from eqparbox. This finds the widest length of the column entries, thereby creating a uniform look across all columns. An optional argument to gaussmat allows you to reset the measurement using a different label, if need be.

\documentclass{article}

\usepackage{mleftright,eqparbox,collcell}

\newcolumntype{R}{>{\collectcell\matcell}r<{\endcollectcell}}
\newcommand{\matcell}[1]{\eqmakebox[\matcelllabel][r]{$#1$}}

\newenvironment{gaussmat}[1][cw]{%
\def\matcelllabel{#1}%
\mleft[\begin{array}{ R R R | R }
}{%
\end{array}\mright]
}

\begin{document}

First, we write this system using matrices:
$\begin{gaussmat} 1 & 2 & 3 & 4 \\ 7 & 5 & 3 & 1 \\ -2 & -3 & -4 & -5 \\ \end{gaussmat}$
We preform $\mathbf{R_2} \rightarrow \mathbf{R_2} - 7\mathbf{R_1}$ and $\mathbf{R_3} \rightarrow \mathbf{R_3} + 2\mathbf{R_1}$:
$\begin{gaussmat} 1 & 2 & 3 & 4 \\ 0 & -9 & -18 & -27 \\ 0 & 1 & 2 & 3 \\ \end{gaussmat}$
Next we $\mathbf{R_2} \rightarrow \mathbf{R_2} \times -\frac{1}{9}$ and $\mathbf{R_3} \rightarrow \mathbf{R_3} - \mathbf{R_2}$:
$\begin{gaussmat} 1 & 2 & 3 & 4 \\ 0 & 1 & 2 & 3 \\ 0 & 0 & 0 & 0 \\ \end{gaussmat}$

\end{document}


You need to compile at least twice with every change in the widest element within your gaussmat.