4

Suppose I have an equation which is too long for one line and I would like to split it over two lines. However, I would like the first line to be left-aligned and the second to be right-aligned w.r.t. the \textwidth. I tried the following versions:

\documentclass{article}

\usepackage{amsmath}

\newcommand{\shortterm}{\mathit{somestrangefunction}(x,y,z)}
\newcommand{\longdefinition}{x+y+z+x^2+xy+xz+y^2+yz+z^2+x^3+y^3+z^3}

\begin{document}

\[
\begin{array}{lcr}
\multicolumn{2}{l}{\shortterm = {}} & \\
 & \multicolumn{2}{r}{\longdefinition}
\end{array}
\]

\begin{flalign*}
 & \shortterm = {} &
\end{flalign*}
\begin{flalign*}
 & & \longdefinition
\end{flalign*}

\begin{flalign*}
 & \shortterm = {} &
\end{flalign*}
\vspace*{-7ex}
\begin{flalign*}
 & & \longdefinition
\end{flalign*}

\end{document}

This yields the following output:

enter image description here

The first version does not fill the \textwidth completely while the second adds a lot of vertical space between the two lines. I can compensate this vertical space with negative \vspace in the third version and obtain more or less the output that I want to have. However, this code is, well, clumsy (and probably both imprecise and not robust w.r.t. achieving the same vertical space between lines). Is there a more elegant solution to this problem that avoids things like adjusting vertical space manually?

5

You could use a multline* environment, with the length paramater \multlinegap set to 0pt.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for \multline* environment

\newcommand{\shortterm}{\textit{SomeStrangeFunction}(x,y,z)}
\newcommand{\longdefinition}{x+y+z+x^2+xy+xz+y^2+yz+z^2+x^3+y^3+z^3}

\begin{document}

\setlength\multlinegap{0pt} % no indentation gaps

\begin{multline*}
\shortterm = \\ 
\longdefinition
\end{multline*}

\end{document}

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.