[Tex/LaTex] Alignment of equals sign in multiple align environments

alignequationshorizontal alignment

I have multiple align environments in my document, separated by a small paragraph of text:

\begin{align*}
  foo &= something very very long compared to the other align
\end{align*}
explanation what I shall do now
\begin{align*}
  foo' &= foo + short
\end{align*}

As the text in the second align is considerably shorter, the = signs don't line up, which is to be expected.

Is there some way to make the two equals signs line up with eachother?

Best Answer

From the amsmath documentation:

The command \intertext is used for a short interjection of one of two lines of text in the middle of a multiple-line display structure ... Its salient feature is preservation of the alignment, which would not happen if you simply ended the display and then started it up again afterwards. \intertext may only appear right after a \\ or \\* command.

So your example would be:

\begin{align*}
  foo &= something very very long compared to the other align \\
\intertext{explanation what I shall do now}
  foo' &= foo + short
\end{align*}

The breqn package also has this capability via its dsuspend environment.


(Added in edit) From the comments, there appear to be a few different ways to achieve this effect. So to help with choosing, here's a sample of all those that I'm aware of. Anyone who knows more is welcome to either add directly to this answer or to make a comment and then I'll add it. Here's the result:

variations on a theme of intertext

and here's the code that produced it:

\documentclass{article}
\thispagestyle{empty}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{breqn}

\begin{document}

\paragraph{Two aligns}

\begin{align*}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
&= a e i + b f g + c d h - a f h - b d i - c e g
\end{align*}
%
Whilst for \(2 \times 2\) we have:
%
\begin{align*}
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
&= a d - b c
\end{align*}

\paragraph{One align, intertext preceeded by \textbackslash\textbackslash} 

\begin{align*}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
&= a e i + b f g + c d h - a f h - b d i - c e g \\
%
\intertext{Whilst for \(2 \times 2\) we have:}
%
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
&= a d - b c
\end{align*}

\paragraph{One align, intertext not preceeded by \textbackslash\textbackslash} 

\begin{align*}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
&= a e i + b f g + c d h - a f h - b d i - c e g
%
\intertext{Whilst for \(2 \times 2\) we have:}
%
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
&= a d - b c
\end{align*}

\paragraph{One align, shortintertext (mathtools)}

\begin{align*}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
&= a e i + b f g + c d h - a f h - b d i - c e g
%
\shortintertext{Whilst for \(2 \times 2\) we have:}
%
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
&= a d - b c
\end{align*}

\paragraph{Using dsuspend from breqn}
~

\begin{dgroup*}
\begin{dmath*}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
= a e i + b f g + c d h - a f h - b d i - c e g
\end{dmath*}
\begin{dsuspend}
Whilst for \(2 \times 2\) we have:
\end{dsuspend}
\begin{dmath*}
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
= a d - b c
\end{dmath*}
\end{dgroup*}


\end{document}
Related Question