1

I have to write a list of two matrix equations. They are almost identical, but the elements in one matrix are slightly larger than the other one, which makes it look badly.

\begin{align}
  \begin{pmatrix}
    -\id & \id \\
     \id & -\id \\
  \end{pmatrix}  u = 0 \\
  \begin{pmatrix}
    \id &   \id \\
     \id &  \id
  \end{pmatrix}  v = 0 
\end{align}

Is there a simple and elegant way to make the two matrices match size? I've found this, but it is a much complex case than mine. Is there something simpler?

carllacan
  • 145
  • 3

3 Answers3

1

Here are two solutions, far from perfect. I use the variants of the matrix environments defined by mathtools, which allow to specify the alignment in a matrix and I modify the value of \arraycolsep when needed.

I also define a \nid math operator, which corrects the spacing between and id in -\id, which is bad.

\documentclass{article}
\usepackage{textcomp} \usepackage{mathtools}
\usepackage[showframe]{geometry}
\DeclareMathOperator{\id}{{id}}
\newcommand*\nid{\ensuremath{-{\id}}}%
\newcommand*\varnid{\ensuremath{\mskip-5mu-{\id}}}
\newcommand*\varid{\ensuremath{\mskip-5mu\phantom{-}{\id}}}%

\begin{document}

\begin{align}
  \begin{pmatrix*}[r]
  \varnid & \id \\
  \id & \nid \\
  \end{pmatrix*} u = 0 \\
  \setlength\arraycolsep{0.9em}
  \begin{pmatrix*}[r]
  \varid & \id \\
  \id & \id
  \end{pmatrix*} v = 0 \\
  \setlength\arraycolsep{1.1em}
  \begin{pmatrix*}[r]
  \id & \id \\
  \id & \id
  \end{pmatrix*} v = 0
\end{align}

\end{document} 

enter image description here

Bernard
  • 271,350
1

I propose two versions, the second one is what I'd prefer.

The calc packages is necessary only for the first solution. As a general rule, never use align without alignment points.

\documentclass{article}
\usepackage{amsmath,calc}
\newcommand{\id}{\mathrm{id}}
\newcommand{\cid}{\makebox[\widthof{$-\id$}]{$\id$}}
\begin{document}
\begin{align}
\begin{pmatrix}
  -\id & \id \\
   \id & -\id \\
\end{pmatrix}  u &= 0 \\
\begin{pmatrix}
  \cid &  \cid \\
  \cid &  \cid
\end{pmatrix}  v &= 0 
\end{align}
A different version
\begin{gather}
\begin{pmatrix}
  -\id & \id \\
   \id & -\id \\
\end{pmatrix}  u = 0 \\
\begin{pmatrix}
  \id &  \id \\
  \id &  \id
\end{pmatrix}  v = 0 
\end{gather}

\end{document}

enter image description here

egreg
  • 1,121,712
1

The package nicematrix has tools designed to address that kind of problem. In particular, there is an environment {NiceMatrixBlock} with a key auto-columns-width to impose the same width for all the columns of the matrices in a given scope. However, you need several compilations.

\documentclass{article}
\usepackage{nicematrix}

\DeclareMathOperator{\id}{{id}}

\begin{document}

\begin{NiceMatrixBlock}[auto-columns-width] \NiceMatrixOptions{right-margin=2pt}

\begin{align} \begin{pNiceMatrix}[r] -\id & \id \ \id & -\id \ \end{pNiceMatrix} u = 0 \ \begin{pNiceMatrix}[r] \id & \id \ \id & \id \end{pNiceMatrix} v = 0 \ \begin{pNiceMatrix}[r] \id & \id \ \id & \id \end{pNiceMatrix} v = 0 \end{align}

\end{NiceMatrixBlock}

\end{document}

Output of the above code

F. Pantigny
  • 40,250