7

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}
8

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

4

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}

enter image description here

  • Shouldn't there be a \! before \begin{multlined} to get correct spacing? – sodd Feb 11 '16 at 12:08
  • 1
    @hooy Yes! I falsely believed that mathtools didn't follow amsmath in this respect. Fixed. – egreg Feb 11 '16 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 '16 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 '16 at 20:59
3

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}

enter image description here

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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.