[Tex/LaTex] Multiline equation inside a split environment

amsmathequations

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}

Best Answer

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}

Output 1

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}

Output 2

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}

Output 3