# Multiline equation inside a split environment

I have a series of equations aligned at = inside a split environment. (They're all actually the same equation, so the left-hand-side is missing in all but the first equation.)

Unfortunately the last equation is super long and doesn't fit into a single line. It needs to be split. I don't what the convention is, but I'd say it should be right-aligned. How do you do this?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= c + c + c + c + c + c + c + c + c + c + c + c \\ % obviously does not work \hfill + c + c + c + c + c + c + c + c + c + c \end{split}$
\end{document}
-

You can make use of mathtools' multlined environment:

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \!\begin{multlined}[t] c + c + c + c + c + c + c + c + c + c + c + c \\ + c + c + c + c + c + c + c + c + c + c \end{multlined} \end{split}$
\end{document}

Note: the \! before the environment is to get correct spacing between = and c.

It's also possible to specify the total width of the two lines (from left margin at first line to right margin at last line) as an optional argument to multlined:

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \!\begin{multlined}[t][10cm] c + c + c + c + c + c + c + c + c + c + c + c \\ + c + c + c + c + c + c + c + c + c + c \end{multlined} \end{split}$
\end{document}

If you want the two lines right aligned, you can set the mathtools key firstline-afterskip to 0pt, either globally or locally:

\documentclass[border=5pt,preview]{standalone}
\usepackage{amsmath,mathtools}
\begin{document}
\mathtoolsset{firstline-afterskip=0pt}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \!\begin{multlined}[t] c + c + c + c + c + c + c + c + c + c + c + c \\ + c + c + c + c + c + c + c + c + c + c \end{multlined} \end{split}$
\end{document}

-

The standard and easiest method is to just add a line to the split and move right by, say, one quad. This is the method I'd prefer, not bothering about alignment.

Alternatively, use multlined from mathtools:

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= c + c + c + c + c + c + c + c + c + c + c + c \\ &\qquad + c + c + c + c + c + c + c + c + c + c \end{split}$
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \mathtoolsset{firstline-afterskip=0pt} \!\begin{multlined}[t] % <---- don't forget \! c + c + c + c + c + c + c + c + c + c + c + c \\ + c + c + c + c + c + c + c + c + c + c \end{multlined} \end{split}$
\end{document}

-
Shouldn't there be a \! before \begin{multlined} to get correct spacing? – hooy Feb 11 at 12:08
@hooy Yes! I falsely believed that mathtools didn't follow amsmath in this respect. Fixed. – egreg Feb 11 at 12:11
@egreg -- and why are you loading both amsmath and mathtools? since mathtools loads amsmath automatically, that is sufficient. – barbara beeton Feb 11 at 20:58
@barbarabeeton If the user doesn't want the second solution, also mathtools might be unwanted. And I prefer to load both in any case. – egreg Feb 11 at 20:59

You could use a stack, for example. If the line heights were uniform, this would work:

\documentclass{article}
\usepackage{amsmath,stackengine}
\stackMath
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \stackengine{\baselineskip}{c + c + c + c + c + c + c + c + c + c + c + c} {{}+ c + c + c + c + c + c + c + c + c + c}{U}{r}{F}{F}{L} \end{split}$
\end{document}

If the stacked rows were of non-standard heights, then this:

\documentclass{article}
\usepackage{amsmath,stackengine}
\stackMath
\begin{document}
$\begin{split} x &= a + a \\ &= b + b + b + b \\ &= \stackengine{5pt}{c + c + c + c + \dfrac{a}{b} + c + c + c + c + c + c + c} {{}+ c + \dfrac{c}{d} + c + c + c + c + c + c + c + c}{U}{r}{F}{F}{S} \end{split}$
\end{document}

It is the 5th argument of \stackengine, given by {r} that defines the alignment of the stack. Other options are {l} and {c}.

-