6

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}
  • 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
6

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

  • 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
4

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

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.