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).

1
  • You could use the environment multline provided by the package amsmath
    – Dox
    Commented Jul 14, 2014 at 15:43

2 Answers 2

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.

3
  • 1
    I think it will have to be 0pt, not Opt, for this to succeed... :-) Commented Jul 14, 2014 at 15:59
  • 1
    Upps... my mistake! Thank you for the correction
    – Dox
    Commented Jul 14, 2014 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
    Commented Jul 15, 2014 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

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

You must log in to answer this question.

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