4

How to align a two-lined equation such that the first line left aligns with the surrounding text and the second line right aligns with the surrounding text?

Example (where the pipes denote the left and right edge of the surrounding text):

|                       |
P(x) =
    a + b + c + d + e + f
|                       |

I fiddled around with flalign, multline, and multlined, but did not get it working the way I want. Prepending a \vphantom to the second line allows me to right-align the second line of the equation. Appending a \vphantom to the first line does not left-align the first line (the \vphantom continues to run in the right margin).

  • You could use the environment multline provided by the package amsmath – Dox Jul 14 '14 at 15:43
4

You could use the environment multline provided by the package amsmath

\documentclass{article}

\usepackage{amsmath}
\setlength\multlinegap{0pt}

\begin{document}

\begin{multline}
P(x) =  \\
   a + b + c + d + e + f
\end{multline}

\end{document}

The \setlength\multlinegap{0pt} assures no indentation of the first line.

  • 1
    I think it will have to be 0pt, not Opt, for this to succeed... :-) – Paul Gessler Jul 14 '14 at 15:59
  • 1
    Upps... my mistake! Thank you for the correction – Dox Jul 14 '14 at 16:01
  • Thanks. I edited your solution slightly by first storing the original \multilinegap value, then set it to zero, then present the equation, and afterwards restore \multilinegap back to its original value – Bart Jul 15 '14 at 11:15
4

Ypu can define the flmultline environment and its starred counterpart:

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}

\makeatletter
\newenvironment{flmultline}
  {\multlinegap=\z@\start@multline\st@rredfalse}
  {\endmultline}
\newenvironment{flmultline*}
  {\multlinegap=\z@\start@multline\st@rredtrue}
  {\endmultline}
\makeatother

\begin{document}
\lipsum*[2]
\begin{flmultline*}
P(x)=\\
aaaaa+bbbbb+ccccc+ddddd+eeeee+fffff+ggggg+hhhhh+iiiii
\end{flmultline*}
\lipsum*[3]
\begin{flmultline}
P(x)=\\
aaaaa+bbbbb+ccccc+ddddd+eeeee+fffff+ggggg+hhhhh+iiiii
\end{flmultline}
\lipsum[4]
\end{document}

The idea is simple: locally set \multlinegap to zero.

enter image description here

  • it's easier multline than this. – skpblack Jul 14 '14 at 16:08
  • 2
    @skpblack With this one still has multline (with the normal setting of \multlinegap) available. – egreg Jul 14 '14 at 16:10

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.