[Tex/LaTex] How to align a set of multiline equations

alignequations

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:

Unaligned

What would like to get instead is something looking more like

Aligned

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}
\begin{equation}
r = s + t (u + v + w)
\label{eq:3}
\end{equation}
\end{document}

Best Answer

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

output of example code

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.

Related Question