28

I would like my multiline equations to look like this:

Left-hand-side of my equation
    = right-hand-side number 1
    = right-hand-side number 2
    = etc.

I know there is a simple way to do this, because I found it a while ago when I was looking for something else. But now that I actually want it, I can't find it again.

I do not require equation numbers.

EDIT: The "simple way to do this" I had been half-recalling was \lefteqn{}, but as far as I understand that only works (and I use the word "works" loosely) within the evil eqnarray environment.

2
  • 2
    \lefteqn probably is the only almost good feature of eqnarray. :)
    – egreg
    Feb 14, 2012 at 22:44
  • 1
    I noticed that mathtools has the command \MoveEqLeft which seems to do exactly the same as my answer below. Apr 17, 2012 at 12:00

6 Answers 6

23

Ok, converting my comment on @egreg's solution into an answer:

\begin{align*}
  \hspace{2em}&\hspace{-2em}Any short or long LHS\\
  &= ax^3 + bx^2 + cx + d \\
  &= f(x)
\end{align*}

This puts the first LHS on a separate line, and the equation is centered correctly, independent of the size of LHS.

Additional note: I've defined a shorthand command for \hspace{2em}&\hspace{-2em} myself. I wasn't sure that putting the & into a command would work, but it does.

1
  • 1
    Yes, a major plus for me about this solution is that I could define such a command as you mention, and then all it would take to modify my existing equations would be to add, say, \lhs in front of them. Feb 15, 2012 at 15:16
17

this should do it.

\documentclass{article}
\usepackage{amsmath}
\multlinegap=30pt
\begin{document}
\begin{multline*}
 \text{Left-hand-side of my equation}\\
  \begin{aligned}
    &= \text{right-hand-side number 1}\\
    &= \text{right-hand-side number 2}\\
    &= \text{etc.}
  \end{aligned}
\end{multline*}
\end{document}

example of multline with aligned

Edit: \multlinegap specifies the indent from the left and right margins. the default is 10pt, but often a wider gap is desirable.

5
  • This answer positions the start of the first line all the way on the left margin, and the rightmost point of the aligned block all the way on the right margin. That leaves the column of equals signs at an arbitrary indentation. I'd prefer a solution where the equals signs were indented the same amount each time I used it, regardless of the lengths of the particular equations, and then the entire thing were horizontally centered. Feb 14, 2012 at 22:53
  • 2
    i've added a modification that will indent the display farther from the margins. this can be set globally in the preamble, or individually for a particular display. if reset for just one display, either enclose the entire display in a group (with {...} or \begingroup ... \endgroup) or reset it before the next display. Feb 15, 2012 at 15:01
  • +1 I think this should be the default behavior of multiline for equations with more than 2 lines!
    – OSE
    Nov 19, 2014 at 23:12
  • @OSE -- that wouldn't necessarily be appropriate if the lines after the first "aren't on the same level" (i think there's an example illustrating this somewhere in the amsmath documentation), but i'll consider adding a suggestion to the amsmath list. Nov 19, 2014 at 23:19
  • @barbarabeeton That's a good point. I think Eq. (2) in Table 3.1 of the amsmath documentation is one such example. In my case, your answer here is exactly what I wanted and it is not too much trouble to add the extra aligned environment.
    – OSE
    Nov 20, 2014 at 18:18
7

Simpler than Werner's but using the same idea for centering with respect to the supposed long left hand side:

\begin{align*}
  \makebox[2em][l]{\text{Here is your LHS that may be very long}} &
  \hspace{-2em}\hphantom{\text{Here is your LHS that may be very long}}\\
  &= ax^3 + bx^2 + cx + d \\
  &= f(x)
\end{align*}

If instead it's one of the right hand sides to be overlong, one can use

\begin{align*}
  \makebox[2em][l]{\text{Not so long LHS}} & \\
  &= ax^3 + bx^2 + cx + d + ay^3 + by^2 + cy + d \\
  &= f(x,y)
\end{align*}

enter image description here

6
  • What would be the deciding factor for which of your two solutions to use? My guess is that I would use the top solution if my left-hand-side were longer than all of my right-hand-sides, and I would use the bottom solution if at least one of my right-hand-sides were longer than my left-hand-side. Is that correct? If so, my situation happens to be the latter case. Feb 14, 2012 at 22:59
  • 1
    Yes, that's the idea. If the LHS is the longest line, it should govern the centering (first solution); with the second solution, the centering will be determined by the full display: two ems (or what you choose) plus the longest RHS.
    – egreg
    Feb 14, 2012 at 23:06
  • 2
    I'm using the following first line: \hspace{2em}&\hspace{-2em}Any short or long LHS. I think this should handle the centering for both cases. Feb 14, 2012 at 23:15
  • 2
    @eldering Yes, it does. Would you write that as an answer?
    – egreg
    Feb 14, 2012 at 23:37
  • @eldering I second egreg. Yours is absolutely the best and most elegant solution for my needs; write it as an answer and I will accept it. Feb 15, 2012 at 2:37
3

You can use a regular align* (from amsmath) and then add some overlapping with box-lengths. Here's a minimal example:

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\newsavebox{\LHS}\savebox{\LHS}{\text{Here is your LHS that may be very long}}
\newsavebox{\relation}\savebox{\relation}{$\qquad\;{=}\;$}
\begin{align*}
  \rlap{\usebox{\LHS}}
  \qquad & \hspace*{\dimexpr\wd\LHS-.5\wd\relation} \\
    &= ax^3 + bx^2 + cx + d \\
    &= f(x)
\end{align*}
\end{document}

The first line (LHS) is set in whichever way you want using \rlap (to obtain a right-overlap). and stored in the box \LHS. The second line contains a blank mockup of \LHS with the appropriate correction of space allocation.

You can change the \qquad to suit your needs, to increase/decrease the horizontal displacement of the start of the =.

3

In case you want to choose the exact point of alignment, you can use plain align(*):

\documentclass{article}
\usepackage{amsmath}
\begin{document}
 \begin{align*}
  ax &+ by + cx \\
     &= 2x + 3y + 4z \\
     &= 17.
 \end{align*}
\end{document}

The resulting multi-line alignment

5
  • 1
    In addition to being a bit of a kludge, this doesn't work in the case that the left-hand-side is a fraction or some other non-&-friendly construct. Feb 14, 2012 at 22:33
  • 2
    I dispute that this is a kludge. It is precisely what the & is designed for, never mind that you may only have seen it used for equals signs. Fractions, I give you.
    – Ryan Reich
    Feb 15, 2012 at 0:08
  • I guess I called it a kludge in that it artificially constrains you to aligning your subsequent lines at discrete locations — namely the boundaries between symbols in your first line. As a further consequence, it means that you can't have reproducible behavior from one instance of doing this to another, since there's no guarantee that next time, there will be a symbol-boundary exactly the same distance into the first line. Feb 15, 2012 at 2:33
  • If you need precise measurements, then yes, you should use one of the other methods. However, it is usually much better design to align visual elements of your equations (or at least align relative to them) than to insist on arbitrary absolute positioning. It is, in addition, much easier to do.
    – Ryan Reich
    Feb 15, 2012 at 2:43
  • This worked for me. It is much simpler and served my purpose. My problem was lengthy fractional construct in the RHS, leaving room for it by moving LHS this way solved it.
    – Ébe Isaac
    Dec 6, 2016 at 14:56
2

Perhaps you are looking for align* from amsmath?

\begin{align*}
  \sum X_i\\
&= \prod Y_i \\
&=\Gamma \text{foo}
\end{align*}
1
  • Possibly \makebox[3em][l]{$\displaystyle Long LHS$}& for the first line, to fix the alignment point.
    – egreg
    Feb 14, 2012 at 17:26

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.