Similar question: How can I make a similar matrix with even column spacing?
The following code is simple to write/read/maintain, but looks terrible.
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{equation*}
\begin{bmatrix*}[r]
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1
\end{bmatrix*}
\end{equation*}
\end{document}
This is because the negative sign adds extra space between the first and second columns, but not between the second and third.
One could naively put a \phantom{-}
in each column, but this isn't right either.
\begin{equation*}
\begin{bmatrix*}[r]
\phantom{-}1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & \phantom{-}1
\end{bmatrix*}
\end{equation*}
This is because we don't need extra space to the left of each column, but an even amount of space between each column.
\begin{gather*}
\begin{bmatrix*}[r]
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1
\end{bmatrix*} \\
\begin{bmatrix*}[r]
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & \phantom{-}1
\end{bmatrix*}
\end{gather*}
Much better. (The second one, compared to the original above it.)
However, in larger matrices, this can easily become hard to read and quite a hassle to maintain. Is there some simple way to tell it to put an equal amount of space (say, between the right hand sides) of columns 1&2, 2&3, 3&4, … ?
Ideally, I'd like the body of my matrices to contain nothing other than the content:
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1
Best Answer
Here's a version that uses a new environment
brmatrix
. For the first column the standardr
column is used, for the other columns we use a new column typeM
which also aligns the content right, but uses a fixed width\@brcolwidth
. As this is a problem if the content may be wider than the cell and overlap with the other columns, an optional parameter for setting the cell width directly has been added.A full example with the standard
bmatrix
in the first and the newbrmatrix
in the other cases:Output: