4

I have a chain of long inequalities; I want to be able to break them up over multiple lines, so that the "left hand side" of the inequality can be 2 lines and the "right hand side" can also be 2 lines. I tried using multline environments but it doesn't work so far.

Ideally, the first line of the "left hand side" of the inequality would be left aligned, the second line of the "left hand side" of the inequality would be right aligned, and then it would go back to being left aligned for the first line of the "right hand side" of the inequality, and finally right aligned for the second line of the "right hand side" of the inequality. With more than 2 inequalities, I would prefer this alternating style if it's possible. Is there an environment for this?

For example

\begin{equation*}
    f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) &\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1\\
    &\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2\\
    &\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 3
\end{equation*}

The answer given so far is not sufficient. What I would like to have is the following output:

\begin{multline*}
f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\ + f(x) + f(x) + f(x) + f(x) + f(x) + f(x)
\end{multline*}
\begin{multline*}
\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\ + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1
\end{multline*}
\begin{multline*}
\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\ + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2
\end{multline*}

etc without using separate multline* environments.

2
  • 2
    I'd say that a combination of align with nested aligned would work, but it would be nice if you posted an example.
    – campa
    May 13 at 10:32
  • An example is added now. May 13 at 11:09

4 Answers 4

3

This uses flalign, \mathllap and \mathrlap. I also tried an alternative style. (The second and third lines were originally one line. I can't decide which looks better.)

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{flalign*}
\mathrlap{f(x) + f(x) + f(x) + f(x) + f(x) + f(x)} \\
&& \mathllap{+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x)} \\
\mathrlap{\quad\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)} \\
&& \mathllap{+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1}\\
\mathrlap{\quad\leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)} \\
&&\mathllap{+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2}
\end{flalign*}

\begin{flalign*}
\mathrlap{f(x) + f(x) + f(x) + f(x) + f(x) + f(x)+ f(x) + f(x) + f(x) + f(x) + f(x)} \\
&& + f(x) & \\
&&& \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \\
&&&& \mathllap{ + f(x) + f(x) + f(x) + 1}\\
&&& \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \\
&&&& \mathllap{ + f(x) + f(x) + f(x) + 2}
\end{flalign*}
\end{document}

demo

4

You can use \shoveleft and \shoveright macro from mathtools package

enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{multline}\nonumber
f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\
+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \shoveright{}
\\
\shoveleft \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\
+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1 \shoveright{}
\\
\shoveleft \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x)\\
+ f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2
\end{multline}

\end{document}
3

Possibly using aligned would solve your situation:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
  \begin{aligned}[b]
    &f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) +f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x)
  \end{aligned}
  &\leq 
  \begin{aligned}[t]
    &f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) + 1
  \end{aligned}
  \\[1ex]
  &\leq
  \begin{aligned}[t]
    &f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) + 2
  \end{aligned}
  \\[1ex]
  &\leq
  \begin{aligned}[t]
    &f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) \\
    &+ f(x) + f(x) + f(x) + f(x) + 3
  \end{aligned}
\end{align*}

\end{document}

enter image description here

1
  • It's not quite what i'm looking for, my equations are too long for this. May 13 at 12:03
2

You have got several good ways to do what you want with LaTeX, so I hope no one will disagree with a way to typeset formulas that break over lines in ConTeXt.

But first of all, let me comment the version with several multline, that you wrote gave you the output you wanted. I ran it and got this:

output from several multline

I think there are some room for improvements: For each multline pair, by flushing left and right, the two lines have too little in common (that problem goes away if you happen to have longer formulas). Also, it probably makes sense to indent line four and six equally much (it happens to be so in your case, since the lines are equally long). I assume that the fact that you have uneven spacing between the three multlines might be the origin to your question.

Let us now turn to how these formulas could be set with ConTeXt. We start by defining a type of formula for the purpose:

\defineformula[long][
    split=yes,
    textalign=middle,
    hang=yes,
    distance=3em,
    spaceinbetween=.5\lineheight,
]

Here, the split=yes tells that we want a formula that can split over lines, textalign=middle tells that we want the whole formula midaligned, hang=yes will allow hanging, distance=3em the amount of hanging, and spaceinbetween=.5\lineheight how much extra lines will spread.

We can now typeset a formula with

\startlongformula
    f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere 
    \skiphere[2]
        + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere
    \alignhere
    \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere 
    \skiphere
        + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1 \breakhere
    \leq  f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere 
    \skiphere
        + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2
\stoplongformula

Here, \breakhere tells us where to break lines, \skiphere (arguments can be explicit lengths, but also numbers, which correspond to the number of \textmargin, which I did not care to set here). Finally, \alignhere tells us where to align. The result looks like this (with some text around):

a formula running over several lines

A good thing with this approach, compared to alignments, is that we work in one formula, running over several lines. This means for example, that we can have fenced material that runs over several lines. We give one example:

\startlongformula
    f(x) + f(x) +  \int_0^1 \left[ f(x) + \frac{f(x)}{g(x)} + f(x) + f(x) \breakhere 
    \skiphere[4]
        + f(x) + f(x) + \frac{f(x)}{g(x)} + f(x) \right]\dd x + f(x) + f(x) \breakhere
    \alignhere 
    \leq f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere 
    \skiphere[2]
        + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 1 \breakhere
    \leq  f(x) + f(x) + f(x) + f(x) + f(x) + f(x) \breakhere 
    \skiphere[2]
        + f(x) + f(x) + f(x) + f(x) + f(x) + f(x) + 2
\stoplongformula

Note that I have increased the numbers in \skiphere. I think that these kind of formulas need some tweaking, and I do not say that this is an optimal version. Note that the square brackets automatically get the right size, even though they are on different lines. Let us look at the output (again with some text around):

a long formula running over several lines, with fenced stuff breaking over lines

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.