How can I use multline within an align environment?

To answer the question, yes the gather, align do not automatically behave as multline does.

multline will left align the first row, the second and all the following ones except the last are centered, and the last line is right aligned. The last lines gets numbered for right equation numbers, and the first one is numbered for the case of left equation numbers.

The gather environment will center all equations and by default number each one, and the align environment has an {rlrl...} alignment and also numbers each equation unless otherwise instructed.

A comprehensive review of mathematics in LaTeX is available in the Mathmode document.


There is no satisfactory solution for a multline behaviour on two consecutive long equations.

Yes, there is.

\documentclass{article}

\usepackage{mathtools}
\usepackage[nopar]{lipsum} % for dummy text only

\begin{document}

\lipsum[1] 
\begin{align}
    A=&\begin{multlined}[t]
    \cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\\=\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi
    \end{multlined}\\
    B=&\begin{multlined}[t]
    \cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\\=\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos \pi
    \end{multlined}
\end{align}
\lipsum[1]

\end{document}

The solution may seem obvious now, but I came across it after two hours of playing around with align, gather, multline, split, alginat, flalign and all its variants; just before I was about to contact Lars Mad­sen (main­tainer of the mathtools package) for an upgrade. It had to be something with an automated format, in pure LaTeX style, not through the use of \quad or \hspace or \vphantom or the like.

enter image description here

It is amazing how such a basic typesetting feature is so unknown. I mean, I couldn't find a solution in the whole Internet! It ought to be included in the the guides and tutorials. Multi-line equations are in our day to day.

I knew there had to be more people demanding a solution to this, which I'm now sharing throughout the forum. It also proves how robust the coding of the mathtools package is, responding successfully to this workaround.

Enjoy!


Based on Peter Grill's comments, what is below is a possibility that could potentially be improved.

\documentclass[fleqn]{book}
\usepackage{mathtools}
\begin{document}
text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text text text text text text
\begin{align}
&\begin{multlined}[b][.87\textwidth]
\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\\=\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi
\end{multlined}\\
&\begin{multlined}[b][.87\textwidth]
\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\\=\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos\pi\cos \pi
\end{multlined}
\end{align}
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\end{document}

It seems that the coefficient 0.87 has to be adapted to the font used in the document