12

I'm having difficulties in setting four square matrices, one on top of each other. They need to have the same size, i.e the same width for aesthetical reasons. Currently,they are very ugly, as shown with this code:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\begin{document}

\begin{align}
    \gamma^0 &=
    \begin{bmatrix}
        0 & \tensor{\sigma}{_2} \\[1em]
        \tensor{\sigma}{_2} & 0
    \end{bmatrix},
    \\
    \gamma^1 &=
    \begin{bmatrix}
        -\, i \tensor{\sigma}{_3} & 0 \\[1em]
        0 & -\, i \tensor{\sigma}{_3}
    \end{bmatrix},
    \\
    \gamma^2 &=
    \begin{bmatrix}
        0 & \tensor{\sigma}{_2} \\[1em]
        -\, \tensor{\sigma}{_2} & 0
    \end{bmatrix},
    \\
    \gamma^3 &=
    \begin{bmatrix}
        i \tensor{\sigma}{_1} & 0 \\[1em]
        0 & i \tensor{\sigma}{_1}
    \end{bmatrix}.
\end{align}

\end{document}

Preview:

enter image description here

The minus signs are the source of the main trouble. I tried using \mathclap around each element (except the 0), and adding some phantom terms to equalize the spacing, but it doesn't work very well and it feels very hacky. So how can I make these matrices of the same size with well balanced elements inside? I hate matrices in LaTeX!!

  • 1
    If you want the matrices to have the same size, there will probably be a lot of extraneous spaces. Can you post an image of what you want the end result to look like? – L. F. Mar 12 at 2:24
  • @L.F., I think the preview I gave above says it all. Yes, some matrices will have some extra spaces, but it would look much better than the actual state. The matrix $\gamma^1$ could have less middle space, to make some compromise. – Cham Mar 12 at 2:28
  • Just to clarify, is that preview what you currently get or what you want to get? An image of what you want to get probably helps, because there are many ways to place the elements with extra space. – L. F. Mar 12 at 2:30
  • 3
    How about this post? MEOW! (Is this the Majorana representation? I also would typeset the i upright.) – user194703 Mar 12 at 2:37
  • @Schrödinger'scat, yep, it's a Majorana representation! By the way, what is your favorite Majorana rep, since there are many? – Cham Mar 12 at 10:17
10

A simple code with eqparbox: I define an \eqmathbox command, which ensures that all math boxes sharing the same tag (M by default) have the width of the largets natural width of their contents. It suffices to use this command with the widest element in each column (two compilations may be required).

Unrelated: needless to load amsmath when you load mathtools: the latter package does it for you.

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$#2$}}

\begin{document}

\begin{align}
    \gamma^0 &=
    \begin{bmatrix}
        0 & \eqmathbox{\tensor{\sigma}{_2}} \\[1em]
       \eqmathbox{\tensor{\sigma}{_2} }& 0
    \end{bmatrix},
    \\[0.5ex]
    \gamma^1 &=
    \begin{bmatrix}
       \eqmathbox{-i\tensor{\sigma}{_3}} & 0 \\[1em]
        0 & \eqmathbox{-i\tensor{\sigma}{_3}}
    \end{bmatrix},
    \\[0.5ex]
    \gamma^2 &=
    \begin{bmatrix}
        0 & \eqmathbox{\tensor{\sigma}{_2}} \\[1em]
        \eqmathbox{-\tensor{\sigma}{_2}} & 0
    \end{bmatrix},
    \\[0.5ex]
    \gamma^3 &=
    \begin{bmatrix}
       \eqmathbox{i\tensor{\sigma}{_1}} & 0 \\[1em]
        0 & \eqmathbox{i\tensor{\sigma}{_1}}
    \end{bmatrix}.
\end{align}

\end{document} 

enter image description here

| improve this answer | |
  • I don't understand your \eqmathbox command. Could you elaborate more on what it's doing? How the matrices could get the same width? This is like magic to me! And is there any conflict between that eqparbox package and others (since I have many in my full doc)? – Cham Mar 12 at 10:25
  • The matrices have the same width because each column of the matrices have the same width. Actually I use \eqmakebox in which the contents is in math mode. As you know, the basic \makebox has a centred contents by default, so the elements in a column will be centred w.r.t. each other, i.e. will be centred in their column. If necessary you can use different tages for each column. For possible conflicts, I can see none – Bernard Mar 12 at 10:32
  • How would you get the same result without eqparbox? Is this equivalent to using \mathclap and adding some phantom spaces? – Cham Mar 12 at 10:38
  • 1
    The width of a column is set by the tag used for \eqmathbox . As the tag is the same (the default M) for all columns of all matrices, these matrices will all have the same total width. Isn't it clear? – Bernard Mar 12 at 11:12
  • 1
    Not at all: it's the way eqparbox works. Each eqparbox, \eqmakebox, &c., uses a tag.The way it works is that all \eqparboxes with the same tag have the same width, namely the natural width of the widest contents with this tag. In the case of \eqmakebox, this tag is specified between brackets because the standard \makebox command specifies its width between brackets. For eqparbox, it would be between braces, like the standard \parbox. Please see the documentation of the package for more details. – Bernard Mar 12 at 17:47
15

The package nicematrix has a feature dedicated to that problem. In an environment {NiceMatrixBlock}, all the matrices created by nicematrix (with {bNiceMatrix} but this environment will create the same result as {bmatrix} would do) will have the same width of columns. Two compilations are necessary.

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}

\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\usepackage{nicematrix}

\begin{document}


\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align}
    \gamma^0 &=
    \begin{bNiceMatrix}
        0 & \tensor{\sigma}{_2} \\[1em]
        \tensor{\sigma}{_2} & 0
    \end{bNiceMatrix},
    \\
    \gamma^1 &=
    \begin{bNiceMatrix}
        -\, i \tensor{\sigma}{_3} & 0 \\[1em]
        0 & -\, i \tensor{\sigma}{_3}
    \end{bNiceMatrix},
    \\
    \gamma^2 &=
    \begin{bNiceMatrix}
        0 & \tensor{\sigma}{_2} \\[1em]
        -\, \tensor{\sigma}{_2} & 0
    \end{bNiceMatrix},
    \\
    \gamma^3 &=
    \begin{bNiceMatrix}
        i \tensor{\sigma}{_1} & 0 \\[1em]
        0 & i \tensor{\sigma}{_1}
    \end{bNiceMatrix}.
\end{align}
\end{NiceMatrixBlock}

\end{document}

result of the above code

| improve this answer | |
  • Feels pretty cool! Now wondering which solution is best, between Bernard's and yours. – Cham Mar 12 at 14:06
  • It depends whether we think we may have to use the other features provided by nicematrix: continuous dotted lines, border matrices, use of the tikz nodes created by nicematrix... – F. Pantigny Mar 12 at 14:14
  • I checked the documentation of nicematrix . I'm now facing a big problem: This package may revolutionize all my matrices, in a major HUGE document, and this means a lot of work. Grrr! – Cham Mar 12 at 14:30
  • 1
    @Cham: Yes, nicematrix is a recent package which uses the most recent versions of expl3, xparse and array. – F. Pantigny Mar 12 at 18:21
  • 1
    @Cham: If you want to use nicematrix for the continuous dotted lines, you won't have a lot of work: you only have to set \NiceMatrixOptions{transparent} and the dotted lines in all {pmatrix}, {bmatrix}, {vmatrix} etc. will be changed automatically without any other change in the geometry of the ouput. On the other side, you can use the environments of amsmath ({pmatrix}, etc.) and of nicematrix ({pNiceMatrix}) in the same document... – F. Pantigny Mar 12 at 18:26
4

Post suggested by Schrödinger's cat's takes care of 'minus' for such spacings, but your matrices have lots of other factors which will need too many if conditions. Best way I found was to add phantom characters and produce the output. I am sure there will be a way to automate this, but if you just want it for three equations, adding phantom manually would serve the purpose.

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\begin{document}

\begin{align}
    \gamma^0 &=
    \begin{bmatrix}
        0 & \phantom{-}\tensor{\sigma}{_2}\phantom{3} \\[1em]
        \phantom{-}\tensor{\sigma}{_2}\phantom{3} & 0
    \end{bmatrix},
    \\
    \gamma^1 &=
    \begin{bmatrix}
        -\, i \tensor{\sigma}{_3} & 0 \\[1em]
        0 & -\, i \tensor{\sigma}{_3}
    \end{bmatrix},
    \\
    \gamma^2 &=
    \begin{bmatrix}
        0 & \phantom{-}\tensor{\sigma}{_2}\phantom{3} \\[1em]
        -\, \tensor{\sigma}{_2}\phantom{3} & \phantom{-}0\phantom{3}
    \end{bmatrix},
    \\
    \gamma^3 &=
    \begin{bmatrix}
        \phantom{- }i \tensor{\sigma}{_1} & \phantom{-} 0 \phantom{3} \\[1em]
        0 & \phantom{-1}i\tensor{\sigma}{_1}
    \end{bmatrix}.
\end{align}

\end{document}

1

| improve this answer | |
  • The matrices don't have exactly the same width. And why the \phantom{3}? – Cham Mar 12 at 10:56
  • @Cham I guess the answerer hoped that \phantom{3} would be the same width as i, but it isn't. – alephzero Mar 13 at 0:34
  • @alephzero yes. I personally feel the answers which automate this space are better than mine. I just tried to hack the problem, but the solutions suggested by other users look better. – Niranjan Mar 13 at 6:07
0
 \documentclass{article}
 \usepackage{amsmath}
 \usepackage[pdftex]{graphicx}
  \usepackage{tikz}


  \usepackage[utf8]{inputenc}

  \begin{document}

  \begin{tabular}{c c}
    $ \gamma^0 =$ &{$\left[
      \begin{tabular}{p{0.75cm}p{0.75cm}}
       0 & $ \sigma _{2} $\\[1em]
       $ \sigma _{2}$ & 0
      \end{tabular}\right]$}
   \end{tabular}\\
        \vspace{1cm}

   \begin{tabular}{cc}
   $ \gamma^1 =$ & {$\left[
      \begin{tabular}{p{0.75cm}p{0.75cm}}
         $ -\iota \sigma_{3}$ & 0 \\[1em]
         0 & $-\iota \sigma_ {3}$
      \end{tabular}\right]$}
   \end{tabular}  
        \vspace{1cm}  

   \begin{tabular}{cc}
       $ \gamma^2 =$ &{$\left[
       \begin{tabular}{p{0.75cm}p{0.75cm}}
        0 & $\sigma_{ 2}$ \\[1em]
        $-\iota \sigma _2$ & 0
       \end{tabular}\right]$}
   \end{tabular}
         \vspace{1cm}

   \begin{tabular}{cc}    
     $ \gamma^3 =$& {$\left[
     \begin{tabular}{p{0.75cm}p{0.75cm}}   
         $ \iota \sigma _{1}$ & 0 \\[1em]
         0 & $ \iota \sigma_{1}$
     \end{tabular}\right]$}
    \end{tabular}

    \end{document}

Here I have used simple latex commands. I have proper latex terms e.g \iota for i. There is a correction in sigma also. I have tries to adjust the tabular columns also.

| improve this answer | |
  • What's wrong with my sigma's ? And I don't agree with iota for the complex "i". – Cham May 27 at 13:57
  • There is nothing wrong. But simple notations are easy to correct. The notation I used are standard latex notations. i can not be iota. Please check with your own hand written documents. The notations are used to create packages which are useful informatting books are in Journal articles. These are useful only we use repeated application. – Vaman Kulkarni May 30 at 4:23

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.