# How to set the "column character width" of a bmatrix?

$$\begin{bmatrix*}[r] 1 & -123 & 1 & 1 \\ 2 & 123 & 2 & 12 \\ 3 & 12 & 3 & 123 \\ -4 & 0 & 4 & -123 \end{bmatrix*}$$


When displayed the columns have widths: [2, 4, 1, 4]. (I am probably misusing the word "width" here. I hope the question is clear though.)

My question is: how do I force all columns to have "character width" equal to 4?

Here is a way. However I don't think it would be particularly nice to the eye. There are optical effects which are not directly linked to the column widths and a correction, if any, should be done based on a case by case appreciation. Compare these two ways:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

$$\begin{bmatrix*}[r] \phantom{-23}1 & -123 & \phantom{-23}1 & 1 \\ 2 & 123 & 2 & 12 \\ 3 & 12 & 3 & 123 \\ -4 & 0 & 4 & -123 \end{bmatrix*}$$

$$\begin{bmatrix*}[r] 1 & -123 & \phantom{-3}1 & 1 \\ 2 & 123 & 2 & 12 \\ 3 & 12 & 3 & 123 \\ -4 & 0 & 4 & -123 \end{bmatrix*}$$

\end{document}


• Thank you. Could you say a few words on what \phantom does? Further, I agree that it is not very aesthetically pleasing.
– Jim
Commented Apr 1, 2018 at 16:18
• It uses the space of its contents (both vertical and horizontal) without printing it. If necessary, you also have \hphantom and \vphantom. I must say the default is not pleasing to the eye either. There's no automatic solution, I think. Commented Apr 1, 2018 at 16:34
• Would it be correct to say that it creates (or reserves) whitespace?
– Jim
Commented Apr 1, 2018 at 18:21
• It creates a white space of the width of its argument. Commented Apr 1, 2018 at 18:50

Here's a solution that employs the siunitx package and its S column type. Like @Bernard in his answer, I do not find the equal-column-widths solution appealing.

\documentclass{article}
\usepackage{mathtools}
\usepackage{siunitx}
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}
$\begin{bmatrix*}[r] 1 & -123 & 1 & 1 \\ 2 & 123 & 2 & 12 \\ 3 & 12 & 3 & 123 \\ -4 & 0 & 4 & -123 \end{bmatrix*}$

% "-3.0" means: set aside space for minus symbol, 3 digits, and 0 decimals
$\left[ \begin{array}{@{} *{4}{T{-3.0}} @{}} 1 & -123 & 1 & 1 \\ 2 & 123 & 2 & 12 \\ 3 & 12 & 3 & 123 \\ -4 & 0 & 4 & -123 \end{array} \right]$
\end{document}