Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I currently have this ugly equation:

enter image description here

The green alignment is just like I want it. The Red one is what I would like to get, but I don't know how.

Here is my MWE:

\documentclass[a4paper]{scrartcl}
\usepackage{amssymb, amsmath} % needed for math
\usepackage[utf8]{inputenc}   % this is needed for umlauts
\usepackage[ngerman]{babel}   % this is needed for umlauts
\usepackage[T1]{fontenc}      % this is needed for correct output of umlauts in pdf

\begin{document}
\begin{align}
    f_1(x) &= a \left (x - \frac{b}{3a} \right )^3 + b \left (x-\frac{b}{3a} \right )^2 + c \left (x-\frac{b}{3a} \right ) + d\\
           &= a \left (x^3 - 3 \frac{b}{3a}x^2 + 3 (\frac{b}{3a})^2 x - \frac{b^3}{27a^3} \right )
             +b \left (x^2 - \frac{2b}{3a} x + \frac{b^2}{9a^2} \right )
             +c x - \frac{bc}{3a} + d\\
            &= ax^3 - bx^2 + \frac{b^2}{3a}x - \frac{b^3}{27 a^2}\\
            & \;\;\;\;\;\;+ bx^2 - \frac{2b^2}{3a}x + \frac{b^3}{9a^2}\\
            & \;\;\;\;\;\;\;\;\;\;\;\; + c x - \frac{bc}{3a} + d\\
            &= ax^3 + \frac{b^2}{3a}\left (1-2+c \right )x + \frac{b^3}{9a^2} \left (1-\frac{1}{3} \right )- \frac{bc}{3a} + d
\end{align}
\end{document}
share|improve this question
    
if it's not necessary to have every line numbered (the presence of only one equals sign for lines (61-61) hints that one number might do), then a nested aligned environment would work. if all lines need to be numbered, then egreg's answer is the best approach. –  barbara beeton Dec 6 '13 at 13:41

2 Answers 2

up vote 6 down vote accepted

Just add suitable phantoms:

\documentclass[a4paper]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amssymb, amsmath}

\begin{document}
\begin{align}
f_1(x) &= a \left (x - \frac{b}{3a} \right )^3 + b \left (x-\frac{b}{3a} \right )^2
             + c \left (x-\frac{b}{3a} \right ) + d\\
       &= a \left (x^3 - 3 \frac{b}{3a}x^2 + 3 (\frac{b}{3a})^2 x
             - \frac{b^3}{27a^3} \right )
             +b \left (x^2 - \frac{2b}{3a} x + \frac{b^2}{9a^2} \right )
             +c x - \frac{bc}{3a} + d\\
       &= ax^3 - bx^2 + \frac{b^2}{3a}x - \frac{b^3}{27 a^2}\\
       &\hphantom{{}=ax^3}+ bx^2 - \frac{2b^2}{3a}x + \frac{b^3}{9a^2}\\
       &\hphantom{{}=ax^3-bx^2} + c x - \frac{bc}{3a} + d\\
       &= ax^3 + \frac{b^2}{3a} (1-2+c)x + \frac{b^3}{9a^2} \left (1-\frac{1}{3} \right )
             - \frac{bc}{3a} + d
\end{align}
\end{document}

enter image description here

share|improve this answer
    
Should equations 3-5 really be three equations? –  Steven B. Segletes Dec 6 '13 at 13:44
1  
This is what the OP seems to want. –  egreg Dec 6 '13 at 13:53

In this solution, I used the tabstackengine package which is now available at http://ctan.org/pkg/tabstackengine. The package introduces tabbing to the existing features of the stackengine package.

So, in this example, I replace the three lines requiring further tabbing with a \tabbedShortstack. I used the default interline gap which is 3pt, but that can be changed with \setstackgap{S}{length}. Also, what showed as three separate equations (3)-(5) in the original should, I think, be only a single equation.

I should also point out that, in tabstackengine, the default tabbing character is & and the default end-of-line character is \\, but that I had to reset those as to not conflict within the align environment.

\documentclass[a4paper]{scrartcl}
\usepackage{amssymb, amsmath} % needed for math
\usepackage[utf8]{inputenc}   % this is needed for umlauts
\usepackage[ngerman]{babel}   % this is needed for umlauts
\usepackage[T1]{fontenc}      % this is needed for correct output of umlauts in pdf
\usepackage{tabstackengine}
\setstackEOL{@}
\setstackTAB{*}
\stackMath
\begin{document}
\begin{align}
    f_1(x) &= a \left (x - \frac{b}{3a} \right )^3 + b \left (x-\frac{b}{3a} \right )^2 + c \left (x-\frac{b}{3a} \right ) + d\               &= a \left (x^3 - 3 \frac{b}{3a}x^2 + 3 (\frac{b}{3a})^2 x - \frac{b^3}{27a^3} \right )
             +b \left (x^2 - \frac{2b}{3a} x + \frac{b^2}{9a^2} \right )
             +c x - \frac{bc}{3a} + d\    &\tabbedShortstack{%
            = ax^3 *- bx^2 *+ \dfrac{b^2}{3a}x - \dfrac{b^3}{27 a^2}@
            * + bx^2 *- \dfrac{2b^2}{3a}x + \dfrac{b^3}{9a^2}@
            **+ c x - \dfrac{bc}{3a} + d%
}\                &= ax^3 + \frac{b^2}{3a}\left (1-2+c \right )x + \frac{b^3}{9a^2} \left (1-\frac{1}{3} \right )- \frac{bc}{3a} + d
\end{align}
\end{document}

enter image description here

Just for edification regarding the tabstackengine package, some of its commands include

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.