10

I have a matrix that looks like

enter image description here

\begin{equation*}  
  \left [\begin{array}{cccccc}  
    0 & 0 & 6 & -6 & 0 & 0 \\  
    0 & 0 & -6 & 6 & 0 & 0 \\  
    0 & 0 & 0 &  0 & 5 & -5 \\ 
    0 & 0 & 0 & 0 & -5 & 5   
\end{array} \right ]  \end{equation*}

How should I sort of align this matrix to make it more symmetrical looking and without the disgusting slight shift due to the negative sign?

  • 3
    Take a look at the bmatrix* environment from mathtools. – barbara beeton Jul 19 at 19:30
12

The mathtools package extends amsmath, among other things, with the matrix* environments, which can take an optional argument for the alignment of their columns (c by default).

I added another solution, for which all columns have the same width, with the \mathllap command (also from mathtools):

\documentclass{article}%
\usepackage{mathtools}


\begin{document}

\begin{equation*}
  \begin{bmatrix*}[r]
    0 & 0 & 6 & -6 & 0 & 0 \\
    0 & 0 & -6 & 6 & 0 & 0 \\
    0 & 0 & 0 & 0 & 5 & -5 \\
    0 & 0 & 0 & 0 & -5 & 5
\end{bmatrix*}
 \end{equation*}

\begin{equation*}\setlength{\arraycolsep}{6pt}
  \begin{bmatrix*}[r]
    0 & 0 & 6 & \mathllap{-}6 & 0 & 0 \\
    0 & 0 & \mathllap{-}6 & 6 & 0 & 0 \\
    0 & 0 & 0 & 0 & 5 & \mathllap{-}5 \\
    0 & 0 & 0 & 0 &\mathllap{-}5 & 5
\end{bmatrix*}
 \end{equation*}

\end{document}

In case there is a minus sign in the first column, it results in a dissymmetry for the spacing of the left and right delimiters, which may look unpleasant to the eye. To make it acceptable, one may add a small space at the end of each row of the matrix, like this:

\begin{equation*}\setlength{\arraycolsep}{6pt}
  \begin{bmatrix*}[r]
    0 & 0 & 6 & \mathllap{-}6 & 0 & 0\enspace \\
    -0 & 0 & \mathllap{-}6 & 6 & 0 & 0\enspace \\
    0 & 0 & 0 & 0 & 5 & \mathllap{-}5\enspace \\
    0 & 0 & 0 & 0 &\mathllap{-}5 & 5\enspace 
\end{bmatrix*}
 \end{equation*}

enter image description here enter image description here

  • 1
    Please add an example showing a matrix with a negative value in the first column. – barbara beeton Jul 19 at 20:53
  • @Barbara Beeton:: That's a challenge! It will destroy symmetry in spacings of left and right bracket. However one can add \; ate the end of each row to make it acceptable – at least from my point of view. – Bernard Jul 19 at 21:08
  • 1
    Yes. That's why (nitpicker that I am) I suggested it. Thought it would be better if shown here, so that an unwary user wouldn't be caught unaware. I agree with your caveat concerning the spacing at the right. – barbara beeton Jul 20 at 20:26
  • 1
    Your wish is my command, Milady! Does it befit you? – Bernard Jul 20 at 20:55
  • 2
    Very nice indeed, both comment and visual. Thank you! – barbara beeton Jul 20 at 21:07
9

You can change column specifiers from c to r and you will obtain:

enter image description here

Is this what you looking for? MWE for above matrix is:

\documentclass[a4paper,12pt]{article}

\begin{document}
\[
\left[\begin{array}{*{6}{r}}
    0 & 0 &  6 & -6 &  0 &  0 \\
    0 & 0 & -6 &  6 &  0 &  0 \\
    0 & 0 &  0 &  0 &  5 & -5 \\
    0 & 0 &  0 &  0 & -5 &  5
\end{array} \right]
\]
\end{document}
  • 2
    Approved: this was the last vote I had available. – Sebastiano Jul 19 at 19:32
  • 3
    @Sebastiano, than you very much! You are very enthusiastic voter ;-) – Zarko Jul 19 at 19:34
  • 3
    Thank you! Very much! – Olórin Jul 19 at 19:46
5

Here there is my proposal. You could to use (for example but there are several strategies) spalign package with has the same approach to build a matrix or array to have minus signs aligned. Here there is a screenshot and a MWE.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{spalign}
\begin{document}
\[ \spaligndelims{[}{]}\spalignmat[r]{0 0 6 -6 0 0; 0  0  -6  6  0  0; 0  0  0   0  5  -5; 0  0  0  0  -5  5} \]
\end{document}
  • 2
    +1 ... interesting package spalign! So far I didn't aware about it. – Zarko Jul 19 at 19:23
  • @Zarko I'm specializing in finding new packages that are very little used but are beautiful and efficacious. – Sebastiano Jul 19 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.