# Aligning multiple equations (which involve cases) at multiple places

I am trying to align this set of equations at two places. Essentially, I want all the equals/neq signs to be aligned. 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} ## 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}
\end{cases}
\end{equation}
and
\begin{equation}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}
=\begin{cases}
\end{cases}
\end{equation}

\begin{alignat}{2}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{M} \bm{\tilde{A}}^{(m)}
&=\begin{cases}
\end{cases}
\shortintertext{and}
\bm{\tilde{A}}^{(n)\intercal} \mathbf{K} \bm{\tilde{A}}^{(m)}
&=\begin{cases}
\end{cases}
\end{alignat}

\end{document}

• Maybe you could use a combination of align and makebox as shown here: How can I align multiple cases environment simultaneously? – leandriis Jul 4 '18 at 10:35
• You are usign cases wrong, it is normally a two column construction, each column separated by &, so remove the \quad and write 0, & n \new m \\ instead – daleif Jul 4 '18 at 10:35

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

• isn't it easier with eqparbox and why isn't there a mathaware version of eqparbox? – daleif Jul 4 '18 at 10:45
• @daleif I was just writing it – egreg Jul 4 '18 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 '18 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 '18 at 11:07

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} 