Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
You could use the environment multline provided by the package amsmath –  Dox Jul 14 at 15:43

2 Answers 2

up vote 4 down vote accepted

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.

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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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