5

As a fleqn fanatic, I run across this problem once every week: when splitting a long formula using amsmath's multline, the middle lines are flushed left:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
  1+2+3+4+5+6+7+8+9+10+11+12 \\
  +13+14+15+16+17+18+19+20+21+22 \\
  +23+24+25+26+27+28+29+30+31
\end{multline}
\end{document}

While this is even documented, I think it is rather borken behaviour.

Is there a way to fix this? I understand that amsmath is essentially frozen, but even some kludgy way, even a \shovecenter that could eventually become part of the thankfully more lively mathtools would be helpful!

P.S. This fundamentalistic adherence of multline to the fleqn option is to be contrasted with the more liberal approach taken by gathered, by the way! The worst of both worlds :-)

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
  \[
    \left(
      \begin{gathered}
        1+2+3+4+5+6+7+8+9+10+11+12 \\
        16+17+18+19+20+21+22 \\
        +23+24+25+26+27+28+29+30+31
      \end{gathered} 
    \right)
  \]
\end{document}
1
  • 2
    (Anyone knows who named the beast multline? I've always wondered why it is not multiline...) Commented Mar 19, 2015 at 19:23

2 Answers 2

9

this is a kludge, but you can take advantage of the \multline \shoveright feature to reposition lines that are erroneously positioned too far to the left:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
  1+2+3+4+5+6+7+8+9+10+11+12 \\
  \shoveright{+13+14+15+16+17+18+19+20+21+22} \kern.1\textwidth \\
  +23+24+25+26+27+28+29+30+31
\end{multline}
\end{document}

outpot of example code

the amount of extra space needed at the end of such a line is (unfortunately) a matter for experimentation.

the positioning bug was reported long ago (in 1996), and a fix is known, but updates to amsmath haven't been scheduled.

in answer to the question posed in a comment as to who gave this beast the name multline, that was michael spivak; the concept, and a good part of the code, were lifted from the original amstex (non-latex!) package.

3
  • Ah! For some reason I imagined \shoveright would ignore any spacing after it in the like. Thanks! Commented Mar 19, 2015 at 20:03
  • Barbara, when you're saying a fix is known, is this maybe a fix one could apply to one's own documents by patching amsmath? I'm currently writing my thesis and fixing all multline environments manually takes a lot of time.
    – sebhofer
    Commented Apr 24, 2015 at 9:01
  • @sebhofer -- on reviewing our internal notes, i find that the "fix" i mentioned is simply a workaround, not a correction in the code. so a patch hasn't been worked out. sorry to report no help here. Commented Apr 24, 2015 at 13:00
6

Just add \hfill as needed to the middle lines. With three lines:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
  1+2+3+4+5+6+7+8+9+10+11+12 \\
\hfill  +13+14+15+16+17+18+19+20+21+22 \hfill\\
  +23+24+25+26+27+28+29+30+31
\end{multline}
\end{document}

enter image description here

With four lines:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
  1+2+3+4+5+6+7+8+9+10+11+12 \\
\hfill  +13+14+15+16+17+18+19+20+21+22 \hfill\hfill\\
 \hfill\hfill +23+24+25+26+27+28+29+30+31+32 \hfill\\
+33+34+35+36+37+38+39+40+41
\end{multline}
\end{document}

enter image description here

Indeed, if the length of the lines is very different, you might have to add some extra spacing besides the \hfill

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .