2

Please, consider the following matrix:

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

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?

2 Answers 2

6

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{equation}
     \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*}
 \end{equation}

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

 \end{document} 

enter image description here

4
  • 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.
    – Bernard
    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.
    – Bernard
    Commented Apr 1, 2018 at 18:50
4

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.

enter image description here

\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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .