28

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?

3 Answers 3

30

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}
4
  • 2
    Also note the \shortintertext from mathtools. Often \intertext produces excessive vertical spacing (in particular if the text is short).
    – Villemoes
    Feb 23, 2011 at 23:41
  • @Villemoes: Very useful to know; I rarely use \intertext because of the excessive spacing. Feb 24, 2011 at 8:41
  • @Herbert, @Villemoes: I've added a sample showing the various possibilities. Thanks for your comments. Feb 24, 2011 at 8:51
  • I think mathtools automatically loads amsmath. Sep 2, 2013 at 2:32
3

I'd like to throw in a (e)plain-version as well:

\input eplain % merely for the command below
\leftdisplays % for making the picture smaller
$$ \def\vmatrix#1{\left|\matrix{#1}\right|}
  \eqalignno{
    \vmatrix{a&b&c\cr d&e&f\cr g&h&i} &= aei + bfg + cdh - afh - bdi - ceg \cr
\noalign{\hbox{Whilst for $2 \times 2$ we have:}} % break away from the align
    \vmatrix{a&b\cr c&d} &= ad - bc
  }
$$
\bye

breakalign

2

The following example shows a manual way of achieving the desired alignment between equation (1) and (2):

enter image description here

\documentclass{article}

\usepackage{mathtools}

\begin{document}

Given that
\begin{equation}
  \text{Long left-hand side} = \mathrlap{a}
    \phantom{\text{Long right-hand side}.}
\end{equation}
where
\[
  b = \text{Some weird definition},
\]
it should be clear that
\begin{equation}
  \phantom{\text{Long left-hand side}}
  \mathllap{c} = \text{Long right-hand side}.
\end{equation}

\end{document}

The above example attempts to align two equations - (1) and (2) - with an additional, ad-hoc, alignment in-between (for whatever reason). The principle of this approach is to identify the longest item on the left-hand and right-hand side respectively, and add them as \phantoms to the equations that have shorter such sides. \mathllap and \mathrlap (from mathtools) provides the means to sneak in the shorter side visually over-top of the \phantom placement.

This approach might be helpful when the content inserted between the two alignments fail under \intertext or \shortintertext.

1
  • Thanks for this solution! I learned a lot from your link and in some cases it is indeed necessary.
    – Ludwik
    May 13, 2019 at 15:14

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.