14

I want to achieve something like the following (for now achieved using Microsoft Paint):

alt text

That is, I want to group a number of multi-line equations within a single equation-type environment (i.e. they have the same number) and have each one aligned like in the "multline"-environment (first line left-aligned, last line right-aligned). Is this possible?

  • See the addendum of this recent answer. – dgs Jun 1 '12 at 16:01
  • 2
    The mathtools package provides a multlined environment that might fit your needs. Maybe this question can help. – egreg Jun 1 '12 at 16:25
  • Sorry, I had overlooked your second requirement in first place. I've posted an answer. – dgs Jun 1 '12 at 16:44
  • The accepted answer is the closest to what I was asking for, but the others help to further map out the space of possibilities here. Thanks! (just noticed I forgot a plus after f_1 and f_2 btw.) – andreasdr Jun 11 '12 at 9:11
10

The \shoveleft and \shoveright commands allow to flush left or right the equations of a multline environment.

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}
    \lipsum[1]
    \begin{multline}
      a_1 + b_1 + c_1 + d_1 + e_1 + f_1\\ 
      \shoveright{g_1 + h_1 + i_1 + j_1 + k_1 + l_1}\\
        \shoveleft{a_2 + b_2 + c_2 + d_2 + e_2 + f_2}\\ 
      g_2 + h_2 + i_2 + j_2 + k_2 + l_2
    \end{multline}
    \lipsum[2]  
\end{document}

enter image description here

Addendum

As pointed out by @barbara beeton, the position of the equation number is ambiguous. This can be solved by using the subsidiary environment multlined provided by mathtools inside an equation (first proposed by @egreg). This approach also benefits from the improved spacing of the equation environment.

enter image description here

\usepackage{mathtools}

\begin{equation}
\begin{multlined}[.7\textwidth]
    a_1 + b_1 + c_1 + d_1 + e_1 + f_1\\ 
    \shoveright{g_1 + h_1 + i_1 + j_1 + k_1 + l_1}\\
    \shoveleft{a_2 + b_2 + c_2 + d_2 + e_2 + f_2}\\ 
    g_2 + h_2 + i_2 + j_2 + k_2 + l_2
\end{multlined}
\end{equation}
  • 2
    unfortunately, this places the equation number at the bottom, rather than in the middle, which isn't optimum for this situation since it then looks like only the second equation is numbered. – barbara beeton Jun 1 '12 at 17:13
  • I agree. I wasn't aware of the multlined environment mentioned by @egreg in the comments to the OP, which in this case is clearly superior. – dgs Jun 1 '12 at 18:34
  • i wasn't aware of that either -- it's clearly a mathtools improvement on amsmath. – barbara beeton Jun 1 '12 at 18:56
7

A regular array can be used for this, if needed:

enter image description here

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\begin{document}
\begin{equation}
  \begin{array}{>{$}p{.55\textwidth}<{$}}
    a_1+b_1+c_1+d_1+e_1+f_1 \\
    \hfill g_1+h_1+i_1+j_1+k_1+l_1 \\[\jot]
    a_2+b_2+c_2+d_2+e_2+f_2 \\
    \hfill g_2+h_2+i_2+j_2+k_2+l_2
  \end{array}
\end{equation}
\end{document}

The paragraph-style column is key and allows \hfill since it has a fixed width. However, it also formats its contents in a box that is in text mode. Switching back to math mode is achieved via array's >{<before>} and <{<after>} specification. For presentation purposes, I chose .55\textwidth. \jot adds a little bigger gap between the equations.

7

Not knowing how wide the text block of your document is, I don't think it's possible to give a completely general or automatic method for achieving the look-and-feel you illustrate in your example. However, as the MWE below suggests, using the split environment provided by the amsmath package inside an equation environment would seem to come reasonably close to having a fully-automated method.

Relative to the visual example you provide, this method has the advantage (in my opinion...) of letting you align the + signs across all four lines of the equation. Note also that because the split environment doesn't provide its own numbering of equation lines, the output automatically has only one equation number that's correctly centered vertically between lines 2 and 3 of the equation.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
  \begin{split}
    a_1+b_1+c_1+d_1+{}&e_1+f_1 \\
    &g_1+h_1+i_1+j_1+k_1+l_1 \\
    a_2+b_2+c_2+d_2+{}&e_2+f_2 \\
    &g_2+h_2+i_2+j_2+k_2+l_2
  \end{split}
\end{equation}
\end{document}

enter image description here

Observe that it's necessary, in lines 1 and 3 of the equation's code, to place a {} construct before the & alignment points so that TeX doesn't think that the preceding + symbol is a unary operator.

  • 2
    i think this (a general approach) is something that should be looked at when amsmath is overhauled. i'll put it on the list. – barbara beeton Jun 1 '12 at 17:15

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.