How to align a set of multiline equations
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.
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
mathtools
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.
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.