# Make column widths of multiple matrix columns equal

I have some gauss matrices in an align* environment, like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}

\newcommand{\BAR}{%
\hspace{-\arraycolsep}%
\strut\vrule % the \vrule is as high and deep as a strut
\hspace{-\arraycolsep}%
}

\begin{document}
\begin{align*}
= &\begin{gmatrix}[p]
1 &  0 &   1 & \BAR &  5 \\
0 &  1 & - 2 & \BAR & -2 \\
0 &  0 &   1 & \BAR &  3 \\
0 &  0 &   3 & \BAR &  9
\rowops
\end{gmatrix} \\
= &\begin{gmatrix}[p]
1 &  0 &   0 & \BAR & 2 \\
0 &  1 &   0 & \BAR & 4 \\
0 &  0 &   1 & \BAR & 3 \\
0 &  0 &   0 & \BAR & 0
\rowops
\end{gmatrix}
\end{align*}
\end{document}


The matrices are aligned, but I also want to keep the column widths the same for every matrix. How would I be able to do this?

Try it Online!

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Henri Menke Mar 23 '16 at 11:54

I made a macro \addwd[]{} that can be placed in any row of the column that needs widening. It makes the mandatory argument the width of the optional argument. By default, the optional argument is the width of "-0".

(Note that I changed "-2" at the end of the second row to "-25" to demonstrate the method for larger width columns)

\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
\usepackage{calc}
\newcommand{\BAR}{%
\hspace{-\arraycolsep}%
\strut\vrule % the \vrule is as high and deep as a strut
\hspace{-\arraycolsep}%
}
\newcommand\addwd[2][-0]{\makebox[\widthof{$#1$}]{$#2$}}
\begin{document}
\begin{align*}
= &\begin{gmatrix}[p]
1 &  0 &   1 & \BAR &  5 \\
0 &  1 & - 2 & \BAR & -25 \\
0 &  0 &   1 & \BAR &  3 \\
0 &  0 &   3 & \BAR &  9
\rowops
\end{gmatrix} \\
= &\begin{gmatrix}[p]
0 &  1 &   0 & \BAR & 4 \\
0 &  0 &   1 & \BAR & 3 \\
0 &  0 &   0 & \BAR & 0
\rowops
\end{gmatrix}
\end{align*}
\end{document}


• It works well, but may make the TeX document hard to read. I'd prefer if there a way in which I don't have to set width using the longest value in each column. – somebody Mar 23 '16 at 12:31
• @somebody Yes, that's the rub, isn't it? – Steven B. Segletes Mar 23 '16 at 12:38