# splitting middle equation of 2 rows

I have a very long equation which does not fit on the page and I am wondering if anybody can help me to align it properly.

\begin{align*}
&(q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\
&=q^{1+2}+q^{1+4}+q^{1+6}+q^{1+8}+q^{3+2}+q^{3+4}+q^{3+6}+q^{3+8}+q^{5+2}+q^{5+4}+q^{5+6}+q^{5+8}+q^{7+2}+q^{7+4}+q^{7+6}+q^{7+8} \\
&=q^3+2q^5+3q^7+4q^9+3q^{11}+2q^{13}+q^{15}
\end{align*}


It would be nice if the helpful if the last line was numbered like other equations but not essential.

-

You could just put part of the equation on the subsequent line and add a \quad or \qquad leading space. However, my preference is to use alignat to get the binary operators aligned, which I think makes it easier to read:

## Notes:

• The alignat solution required the use of \mathclap so that those equations did not effect the alignment. This is available in the mathtools package (which already includes amsmath).
• As per barbara beeton's suggestion, I added a {} for the last = within the \mathclap. This make the = a binary operator and yields proper alignment.

## Code:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{align*}
&(q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\
\end{align*}
\begin{align*}
&(q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\
\end{align*}
Alternatively, you could use \verb|alignat*|
\begin{alignat*}{4}
&\mathrlap{(q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8)} \\
\end{alignat*}
\end{document}

-
The alignat is what I think I'm looking for. What is the code for alignat? I can't seem to find how to use it properly. Thanks. – user50291 Apr 21 '14 at 21:52
@user50291: Opps, forgot to update the code. The alignat code is there now. – Peter Grill Apr 21 '14 at 22:00
@Manuel: I am not familiar with \MoveEqLeft. Perhaps you should add an answer using that? – Peter Grill Apr 21 '14 at 22:03
the last = sign isn't aligned. i think you can fix it by preceding it with {}. – barbara beeton Apr 22 '14 at 6:08
The first of these solutions, and @Thruston 's eblow, use the alignment to clarify the semantics of the expansion. Some such solution is best for your readers. – Ethan Bolker Apr 22 '14 at 14:25

Here's a solution that takes a different approach to demonstrating the multiplication of the indices, by lining them up to make the totals more obvious. Personally I like doing this sort of thing using Knuth's halign structure, as I think it's simpler, but if you are just starting out you may prefer to use more standard LaTeX facilities instead. So there are two versions here.

\documentclass{article}
\usepackage{mathtools}
% so we can put the equation number at the bottom
\begin{document}
First using plain TeX facilities, embedded in LaTeX.
\vbox{\openup3pt\halign{\quad#&&{}#\hfil\cr \omit \left(q^1 +q^3 +q^5 +q^7\right)\left(q^2 +q^4 +q^6 +q^8\right)\hidewidth\cr \noalign{\smallskip} & =q^{1+2} & +q^{1+4} & +q^{1+6} & +q^{1+8} \cr & & +q^{3+2} & +q^{3+4} & +q^{3+6} & +q^{3+8} \cr & & & +q^{5+2} & +q^{5+4} & +q^{5+6} & +q^{5+8} \cr & & & & +q^{7+2} & +q^{7+4} & +q^{7+6} & +q^{7+8} \cr \noalign{\smallskip} & =q^3 & +2q^5 & +3q^7 & +4q^9 & +3q^{11} & +2q^{13} & +q^{15} \cr }}

And now using an \texttt{alignat} environment
\begin{alignat*}{8}
\mathrlap{\left(q^1 +q^3 +q^5 +q^7\right)\left(q^2 +q^4 +q^6 +q^8\right)}\\[\smallskipamount]
& \quad && =q^{1+2} && +q^{1+4} && +q^{1+6} && +q^{1+8} \\
&       &&          && +q^{3+2} && +q^{3+4} && +q^{3+6} && +q^{3+8} \\
&       &&          &&          && +q^{5+2} && +q^{5+4} && +q^{5+6} && +q^{5+8} \\
&       &&          &&          &&          && +q^{7+2} && +q^{7+4} && +q^{7+6} && +q^{7+8}\\[\smallskipamount]
&       && =q^3     && +2q^5    && +3q^7    && +4q^9    && +3q^{11} && +2q^{13} && +q^{15}\tagmehere
\end{alignat*}

\end{document}


## Notes

1. The OP wanted the equation number at the end. In the plain TeX version this happens naturally since I've wrapped the alignment in a vbox (which has lots of height but not much depth) and the equation number gets lined up with the baseline. If you wanted the number centred, you would use a vcenter instead of the vbox so that the baseline was in the middle. In the alignat version we have to put the tag in by hand to get it at the bottom, but I use a little macro to update the equation counter neatly (borrowed from here). I considered using an alignedat inside an equation - this puts the equation number amidships, but that's not really what was wanted.

2. In the plain solution the \openup3pt adds some extra space between the lines so that they look a bit better with all the superscripts. I use \noalign{\smallskip} to insert some extra space where we want it. In the LaTex version we don't the extra openup space as this is done automagically, and we put the extra line spaces in just by using the optional argument to the end of line marker.

3. The alignat requires all those double &&s because it is assuming that I have a bunch of equations and it therefore makes alternate columns align left and right. No such nuisance in the halign.

-
this does make some things apparent that i don't see in other approaches, but it would be nice to have a latex solution. use mathtools (loads amsmath). try embedding an alignedat structure in an equation to get a single number; use && to get the proper left alignment. you'll have to choose a (possibly) arbitrary alignment point in the first line and use \mathrlap to keep from fouling up the other lines. i won't have tex access for another week, but i'd like to see this answer provided, so i'm making a suggestion instead. – barbara beeton Apr 22 '14 at 14:47
@barbarabeeton I'll have a go. Just occasionally, the plain TeX alignment facilities are easier to use, I find. – Thruston Apr 22 '14 at 18:43

Starting with @PeterGrill 's answer, using the \MoveEqLeft command provided by mathtools. Still, you can't get rid of one last \quad or \qquad, but I think the \MoveEqLeft is useful here.

\documentclass{scrartcl}

\usepackage{mathtools}

\begin{document}

\begin{align}
\MoveEqLeft (q^1 + q^3 + q^5 + q^7) (q^2 + q^4 + q^6 + q^8) \nonumber \\
&= q^{1+2} + q^{1+4} + q^{1+6} + q^{1+8} + q^{3+2} + q^{3+4} + q^{3+6} + q^{3+8} \nonumber \\
&\qquad + q^{5+2} + q^{5+4} + q^{5+6} + q^{5+8} + q^{7+2} + q^{7+4} + q^{7+6} + q^{7+8} \nonumber \\
&= q^3 + 2q^5 + 3q^7 + 4q^9 + 3q^{11} + 2q^{13} + q^{15}
\end{align}

\end{document}


About the \nonumber method… I have nothing to say, it works, but may be there are other better solutions.

-

Here are three variations on the numbering them, all using \MoveEqLeft. show an unnumbered group of equations, or all numbered but the middle one, or one number for the whole group.

\MoveEqLeft is defined in mathtools specifically for the case of a long first line in an alignment. I use it in a slighly different context but the global idea is the same: this command replaces the ampersand and move the firstline by 2 em by default; here I suse the optional argument, which is the number of em's by which thhe first line is moved. Actually, it can be applied to any line of an alignment, but I think it can make sense only for the first.

The second idea is to put the second line in a multlined environment, also defined in mathtools.

 \documentclass[a4paper, 11pt]{book}

\usepackage[utf8]{inputenc}
\usepackage[showframe, nomarginpar]{geometry}

\usepackage{mathtools}

\begin{document}

\begin{align*}
\MoveEqLeft[4] (q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\
&=\begin{multlined}[t]
q^{1+2}+q^{1+4}+q^{1+6}+q^{1+8}+q^{3+2}+q^{3+4}+q^{3+6}+q^{3+8}\\+ q^{5+2}+q^{5+4}+q^{5+6}+q^{5+8}+q^{7+2}+q^{7+4}+q^{7+6}+q^{7+8}
\end{multlined}\\
&=q^3+2q^5+3q^7+4q^9+3q^{11}+2q^{13}+q^{15}
\end{align*}

\begin{align}
\MoveEqLeft[4] (q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\
&=\begin{multlined}[t] \notag
q^{1+2}+q^{1+4}+q^{1+6}+q^{1+8}+q^{3+2}+q^{3+4}+q^{3+6}+q^{3+8}\\+ q^{5+2}+q^{5+4}+q^{5+6}+q^{5+8}+q^{7+2}+q^{7+4}+q^{7+6}+q^{7+8}
\end{multlined}\\
&=q^3+2q^5+3q^7+4q^9+3q^{11}+2q^{13}+q^{15}
\end{align}

\begin{aligned} \MoveEqLeft[4] (q^1+q^3+q^5+q^7)(q^2+q^4+q^6+q^8) \\ &=\begin{multlined}[t] q^{1+2}+q^{1+4}+q^{1+6}+q^{1+8}+q^{3+2}+q^{3+4}+q^{3+6}+q^{3+8}\\+ q^{5+2}+q^{5+4}+q^{5+6}+q^{5+8}+q^{7+2}+q^{7+4}+q^{7+6}+q^{7+8} \end{multlined}\\ &=q^3+2q^5+3q^7+4q^9+3q^{11}+2q^{13}+q^{15} \end{aligned}

\end{document}


-