# How to align a set of multiline equations

I am trying to align a set of long equations, that are themselves align environments as most of them are spreading on multiple lines.

Currently I just have a sequence of align environments, with each equation inside in order to align the pieces of each equations. I am attaching a screenshot of the result:

What would like to get instead is something looking more like

which is the same set of equations after going through the copyediting office of a journal and looks much better.

Here is a MWE. I would like all three equations to align on the equal sign.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
a & =  b + c + d \nonumber \\
& \qquad + e + f + g
\label{eq:1}
\end{align}
\begin{align}
k & = l + m + n + m + n + m + n \nonumber \\
& \qquad + o + p + q
\label{eq:2}
\end{align}
$$r = s + t (u + v + w) \label{eq:3}$$
\end{document}

-
Welcome to TeX.sx! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  N.N. Feb 13 '12 at 19:57
Thanks a lot! I just followed your advice. –  Thomas 122 Feb 13 '12 at 20:08
It would be a lot easier if you provided the code in terms of a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Feb 13 '12 at 20:17

without an actual example, here's how i interpret what you want.

and here is the input:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
This example shows \verb|aligned| equations within
an \verb|align| environment.
\begin{align}
\phantom{i + j + k}
&\begin{aligned}
\mathllap{a} &= b + c + d\\
&\qquad + e + f + g + x + y + z
\end{aligned}\\
&\begin{aligned}
\mathllap{i + j + k} &= l + m + n\\
&\qquad + o + p + q
\end{aligned}
\end{align}
\end{document}


the longest left-hand element is inserted at the beginning as a \phantom and the lengths of the left-hand elements of the individual aligned segments are made "invisible" by lapping them to the left using \mathllap from the thmtools package.

the original answer was (correctly) noted to align the segments properly only when the left-hand sides had the same length. this modification overcomes that problem.

-
This solution does not align the two equations. It looks aligned here because the right hand sides are the same lengths, but it won't be if one line is longer than the others. –  Thomas 122 Feb 13 '12 at 21:16
oops! forgot a couple of ampersands. updated version coming up. –  barbara beeton Feb 13 '12 at 21:26
Ok now it works great. Thanks! –  Thomas 122 Feb 13 '12 at 21:40
only works if the left hand sides have the same lengths? –  user1834164 May 21 '13 at 11:45
@user1834164 -- you're correct about the lengths of the left-hand elements. but it can be salvaged. adding that ... –  barbara beeton May 21 '13 at 12:22

As an extension to barbara's answer, you could wrap only the right-hand side of your equations into aligned subenvironments. This allows you to align the equal signs of the separate equations independent of the size of left- or right-hand sides.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
This example shows \verb|aligned| equations within
an \verb|align| environment.
\begin{align}
a &= \begin{aligned}[t]
&b + c + d +\\
&c + e + f + g + h + i
\end{aligned}\\
k &= \begin{aligned}[t]
&l + m + n\\
&+ o + p + q
\end{aligned}
\end{align}
\end{document}


The plus sign on the second line of the second equation does not exactly match up because it's a mathbin symbol. Maybe someone with more TeX knowledge could comment on how to best fix that.

-
Thanks, that works too. The difference I see is that equation numbers are on the top line of each equation, whereas when the whole equation is in the 'aligned' environment the equation numbers are vertically centred. Is there a way to control that? –  Thomas 122 Feb 13 '12 at 21:50
@eldering -- to get the matching spacing after the first plus sign in the last line, precede it by an empty group, {}. –  barbara beeton Feb 13 '12 at 22:11

You can also use the split environment inside the align environment, using an ampersand (&) where you want the alignment to take place. Here is a MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
\begin{split}\label{eq:1}
a ={}& b + c + d\\
& + e + f + g
\end{split}\\
\begin{split}\label{eq:2}
k ={}& l + m + n + m + n + m + n\\
& + o + p + q
\end{split}\\
r ={}& s + t (u + v + w)\label{eq:3}
\end{align}
\end{document}


Notice that the last equation is not inside a split environment, but still aligns with the rest, since it's still inside the align environment.

The output looks like this:

Note the empty groups ({}) before the ampersands. Without these, there would be no kerning applied between the equals signs and the character afterwards, because the alignment breaks the box. While the empty groups don't do anything themselves, in math mode the symbols before them add kerning as though the empty groups were ordinary characters. This enables TeX to choose the most appropriate spacing. If the ampersands were placed before the equal signs, the align environment would kern around the equal signs as it should with no such hassle, but then the addition sign of the split equation would lie uncomfortably far back, requiring some sort of manual tweaking of its own.

-

Here is an align-only version of your equations:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\myvec}[1]{\hat{\mathbf{#1}}}% Vector notation
\begin{document}
\begin{align}
f_{\textit{P},\textit{P}}\left(\myvec{n};\myvec{m}\right) &= \frac{\omega^2}{4\pi\rho\alpha^4} \textit{AF}\left(k_\alpha\left(\myvec{n}-\myvec{m}\right)\right) \nonumber \\
&\mathrel{\phantom{=}} \times\left\{\left(\lambda+\mu\right)^2\eta_N+\left(\lambda+\mu\right)\mu\eta_N\left(\cos 2\phi+\cos 2\theta\right)\right. \nonumber \\
&\mathrel{\phantom{=}} \left.\kern-\nulldelimiterspace +\;\mu^2\eta_N\cos 2\phi\cos 2\theta+\mu^2\eta_T\sin 2\phi\sin 2\theta\cos\varphi\vphantom{\left(\lambda\right)^2}\right\}, \\
f_{\textit{P},\textit{SH}}\left(\myvec{n};\myvec{m},\myvec{q}\right) &= \frac{\omega^2}{4\pi\rho\alpha\beta^3} \textit{AF}\left(k_\alpha\myvec{n}-k_\beta\myvec{m}\right) \nonumber \\
&\mathrel{\phantom{=}} \times\left(-\mu^2\eta_T\right)\sin 2\phi\cos\theta\sin\varphi, \\
f_{\textit{P},\textit{SV}}\left(\myvec{n};\myvec{m},\myvec{q}\right) &= \frac{\omega^2}{4\pi\rho\alpha\beta^3} \textit{AF}\left(k_\alpha\myvec{n}-k_\beta\myvec{m}\right) \nonumber \\
&\mathrel{\phantom{=}} \times\left\{\left(\lambda+\mu\right)\mu\eta_N\sin 2\theta+\mu^2\eta_N\cos 2\phi\sin 2\theta\right. \nonumber \\
&\mathrel{\phantom{=}} \left.\kern-\nulldelimiterspace -\;\mu^2\eta_T\sin 2\phi\cos 2\theta\cos\varphi\right\},
\end{align}
\end{document}
​


Some of the adjustments include

• Using \mathrel for proper spacing around hidden = (included via \phantom);
• Some negative \nulldelimiter kerning around missing \left. delimiters (otherwise there would be additional spacing introduced between operator/operand);
• Height adjustment for multi-line \left\{ and \right\} pairs.

As a common thread, it may be useful to peruse Herbert Voß' mathmode document.

-

This is a way to accomplish this for small amounts of text by using the \intertext command.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
This example shows \verb|aligned| equations within
an \verb|align| environment.
\begin{align}
\begin{aligned}
a &= b + c + d\\
&\qquad + e + f + g
\end{aligned}\\
\begin{aligned}
k &= l + m + n + m + n + m + n\\
&\qquad + o + p + q
\end{aligned}
\end{align}

This example shows text and  equations within
an \verb|align| environment.
\begin{align}
a &= b + c + d\\
&\qquad + e + f + g
\intertext{A small amount of text can go here with $x=2$ inline math
and     $$\int_a^b f(x)\,dx=F(b)-F(a)$$ (even inline math). But not a lot
of text. }
k &= l + m + n + m + n + m + n\\
&\qquad + o + p + q
\end{align}

\end{document}

-
\begin{align}
\ni Tdij (Ti,Tj,Sk,t) & = Tdij(Ti,Tj,Sk,t) \nonumber \\
& Tddir (Ti,Tj,Sk,t) \bigoplus \nonumber \\
& Tdrecom (Ti,Tj,Sk,t) \bigoplus \nonumber \\
& Tdiv (Ti,Tj,Sk,t)
\label{eq:1}
\end{align}


will provide following output

-
How does this address the original post in such a way that hasn't already been addressed by the other answers? –  Werner Feb 20 at 7:24