# Aligning Multiple Columns in an Equation

I have the following equation:

\documentclass[a4paper,oneside]{scrbook}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
X & = A * A * \Big( A * A * A * A
&   + AA * AA \\
&&  + AA * AA \\
&&  + AA * AA & \Big)
\\
&  + B * B * \Big( B * B
&  + BB * BB \\
&& + BB * BB \\
&& + BB * BB & \Big)
\\
&  + C * C * \Big( C * C * C * C * C * C
&  + CC * CC \\
&& + CC * CC \\
&& + CC * CC & \Big)
\\
&  + D * D + D * D \\
&  + D * D + D * D
\end{aligned}
\end{equation*}

\end{document}


I'd like to have the double-characters AA BB CC to be aligned more to the left like in the CC example (but even there is a small gap).
I'd like to have it in one equation, so it will have one number assigned to it. I tried it for almost 5h to do it on my own, but nevertheless what I did, I wasn't able to align it properly within the equation.

How to align this?

• I cannot decide which of the answers of LaRiFaRi or Steven B. Segletes to choose as answer. LaRiFaRi's is easier to use with bigger equations, but the + and = do not exactly line up. I had to change &\hphantom{={}} to &\hphantom{\ }. Or Steven's answer, what is exactly doing what I want, but with the tradeoff of more splitting into parts of an bigger equation and I have had to install tabstackengine. – Buni Sep 17 '14 at 7:40

Here is a solution using aligned inside of align environments. The split is only needed in order to get one vertically centred label on the right. If you want to have it on the first line, you will have to get rid of this and \notag all lines but the first (or last).

% arara: pdflatex

\documentclass[a4paper,oneside]{scrbook}
\usepackage{amsmath}

\begin{document}
\begin{align}
\begin{split}
X &= \begin{aligned}[t]
A * A * \Bigl( A * A * A * A &+ AA * AA \\
&+ AA * AA \\
&+ AA * AA\Bigr)\\
\end{aligned}\\
&\hphantom{={}}\begin{aligned}[t]
{}+ B * B * \Bigl( B * B &+ BB * BB \\
&+ BB * BB \\
&+ BB * BB\Bigr)
\end{aligned}\\
&\hphantom{={}}\begin{aligned}[t]
{}+ C * C * \Bigl( C * C * C * C * C * C &+ CC * CC \\
&+ CC * CC \\
&+ CC * CC\Bigr)
\end{aligned}\\
&\hphantom{={}}+ D * D + D * D \\
&\hphantom{={}}+ D * D + D * D
\end{split}
\end{align}
\end{document}


• @Buni glad I could help. You should not align the = and the +-sign. Instead of the \hphantom{} you can use a \quad which should have the same width. See here for the different alignments and here for some alignment rules. – LaRiFaRi Sep 17 '14 at 7:27
• Thanks for your quick answer! Sorry I had to remove my answer, I was too fast with my decision, I should have test the other answer first. I will try your suggestions now. – Buni Sep 17 '14 at 7:43
• I choose this as my answer since its straigthforward to use even on large equations without splitting the equation too much (so I am able to format the equation in my *.tex-file almost the way it should look in the pdf). – Buni Sep 18 '14 at 13:11

Here's a way to do it with tabular stacks

\documentclass[a4paper,oneside]{scrbook}
\usepackage{amsmath,tabstackengine}
\begin{document}
\begin{equation*}
\stackMath
\TABbinary\setstackgap{L}{1.3\baselineskip}
\savestack{\Aterm}{\Longunderstack[l]{%
{}+ AA * AA\\ {}+ AA * AA \\ {}+ AA * AA \Big)%
}}
\savestack{\Bterm}{\Longunderstack[l]{%
{}+ BB * BB\\ {}+ BB * BB \\ {}+ BB * BB \Big)%
}}
\savestack{\Cterm}{\Longunderstack[l]{%
{}+ CC * CC\\ {}+ CC * CC \\ {}+ CC * CC \Big)%
}}
\alignShortstack{
X & = A * A * \Big( A * A * A * A \Aterm \\
&  + B * B * \Big( B * B \Bterm \\
&  + C * C * \Big( C * C * C * C * C * C \Cterm \\
&  + D * D + D * D \\
&  + D * D + D * D
}
\end{equation*}
\end{document}


• Ahh, thank you, but I meant that the AA and BB are the same as on the left as the CC – Buni Sep 16 '14 at 14:40
• @Buni Please see revision. – Steven B. Segletes Sep 16 '14 at 14:56
• Thank you, that is exactly what I was looking for! I am using MikTeX (and its package manager) is tabstackengine available in another package, where I do not have to manually install it? – Buni Sep 17 '14 at 7:35
• @Buni. There really is no installation, per se. Go to ctan.org/pkg/tabstackengine and click on the "Sources" line. Then you can download the pdf and sty directly. The sty can be placed in your working directory, until such time that you figure out where it goes. By default in MikTeX, it goes in C:\Users[your user name here]\AppData\Roaming\MiKTeX\2.9\tex\latex and then you would need to update the filename database (FNDB). – Steven B. Segletes Sep 17 '14 at 10:10