3

I am trying to align this set of equations at two places. Essentially, I want all the equals/neq signs to be aligned.

enter image description here

I am aware of the alignat environment which allows you to align an equation at multiple points. However, this doesn't seem to work as I have \begin{cases} within my equation (cases requires a \\ which appears to be confusing alignat?)

When I try use \begin{alignat}{2}

enter image description here

Code

\documentclass[12pt,a4paper]{report}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{bm}

\begin{document}

\begin{equation}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)} 
            =\begin{cases}
               0, \quad n \neq m\\
               1, \quad n = m
            \end{cases}
\end{equation}
and
\begin{equation}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}                                  
            =\begin{cases}
               0, \quad n \neq m\\
               \omega_n^2, \quad n = m.
            \end{cases}
\end{equation}

\begin{alignat}{2}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)} 
            &=\begin{cases}
               0, \quad n &&\neq m\\
               1, \quad n &&= m
            \end{cases}
\shortintertext{and}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}                                  
            &=\begin{cases}
               0, \quad n &&\neq m\\
               \omega_n^2, \quad n &&= m.
            \end{cases}
\end{alignat}

\end{document}
2

2 Answers 2

3

Using \shortintertext is OK, but in order to align the conditions, you need some more work.

\documentclass[12pt,a4paper]{report}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{calc}

\begin{document}

\begin{align}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)} 
&=\begin{cases}
  \mathmakebox[\widthof{$\omega_n^2,$}][l]{0,} & n \neq m,\\
  \mathmakebox[\widthof{$\omega_n^2,$}][l]{1,} & n = m,
\end{cases}
\\
\shortintertext{and}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}                                  
&=\begin{cases}
  \mathmakebox[\widthof{$\omega_n^2,$}][l]{0,} & n \neq m,\\
  \omega_n^2, & n = m.
\end{cases}
\end{align}

\end{document}

enter image description here

A different implementation with eqparbox: the defined command \matheqbox takes two arguments, the first is an arbitrary label for the internal workings. Different alignments need different labels.

\documentclass[12pt,a4paper]{report}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{eqparbox}

\newcommand{\matheqbox}[3][\displaystyle]{%
  \eqmakebox[#2][l]{$#1#3$}%
}

\begin{document}

\begin{align}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)} 
&=\begin{cases}
  \matheqbox{A}{0,} & n \neq m,\\
  \matheqbox{A}{1,} & n = m,
\end{cases}
\\
\shortintertext{and}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}                                  
&=\begin{cases}
  \matheqbox{A}{0,} & n \neq m,\\
  \matheqbox{A}{\omega_n^2}, & n = m.
\end{cases}
\end{align}

\end{document}
4
  • isn't it easier with eqparbox and why isn't there a mathaware version of eqparbox?
    – daleif
    Jul 4, 2018 at 10:45
  • @daleif I was just writing it
    – egreg
    Jul 4, 2018 at 10:47
  • I was faster ;-), I thought I'd seen a math aware version of eqparbox but probably remembered wrong, would be nice to have a version where we don't need the $...$
    – daleif
    Jul 4, 2018 at 10:48
  • The \matheqbox probably ought to be made with xparse such that one could also access the second optional arg of \eqmakebox, but that is just details.
    – daleif
    Jul 4, 2018 at 11:07
3

Here is a solution using eqparbox and align

The good thing with eqparbox is that it keeps track of the widest entry automatically at the cost of having to compile a few times. The W is the unique name for this box set.

Just remember that the contents inside \eqparbox is text, so we need the $...$.

Or use egregs \matheqbox addition in his answer

\documentclass[12pt,a4paper]{report}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{eqparbox}
\begin{document}

\begin{align}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)} 
            &=\begin{cases}
               \eqmakebox[W][l]{$0$,} & n \neq m\\
               \eqmakebox[W][l]{$1$,} & n = m
             \end{cases}
             \\
\intertext{and}
            \bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}                                  
            &=\begin{cases}
              \eqmakebox[W][l]{$0$,} & n \neq m\\
              \eqmakebox[W][l]{$\omega_n^2$,}& n = m.
            \end{cases}
\end{align}


 \end{document}

enter image description here

You must log in to answer this question.

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