Aligning different parts of an equation with certain spots in the line above
You can use the alignat
environment from the amsmath package.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{6}
X&={}& A&AA &{}+{}& B&B&B &{}+{}& C&C&C \\
&={}& &a &{}+{}& &b& &{}+{}& &c&
\end{alignat}
Note that the align
environment uses a rcl
alignment for each of the components. That's why your output seems to be bunched together in "mini-equations".
Here are a couple of options, using amsmath
or not:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\makeatletter
\newcommand{\cmathbox}[2][x]{%
\settowidth{\@tempdima}{$#1$}%
\makebox[\@tempdima][c]{$#2$}%
}
\makeatother
\begin{document}
Original using \verb|align*|:
\begin{align*}
X&=A&AA &+ B&BB &+ C&CC \\
&= &a &+ &b &+ &c
\end{align*}
Using \verb|alignat*|:
\begin{alignat*}{3}
X&=AAA &&+ BBB &&+ CCC \\
&=\cmathbox[AAA]{a} &&+ \cmathbox[BBB]{b} &&+ \cmathbox[CCC]{c}
\end{alignat*}
Using \verb|array|:
\[
\begin{array}{r@{{}\mathrel{=}{}}c*{2}{@{{}\mathbin{+}{}}c}}
X & AAA & BBB & CCC \\[\jot]
& a & b & c
\end{array}
\]
\end{document}
My alignat
solution differs slightly from @IanThompson's. His would be more general if you don't want to horizontally centre the expression components. The array
solution mimics the behaviour via correct spacing around the operators (relational and binary), as well as vertically between expressions (using \jot
which is 3pt
).
I often resort to using \makebox[<size>]{<new text>}
which uses a box as wide as <size}
to place the <new text>
.
To compute the <size>
I use \withdof{<old text>}
form the calc
package. By default this will center the <new text>
, but you can also specify the alignment with [l]
for left, [r]
for right, or [c]
for center. In the second example below I left aligned the a
and b
, and right aligned the c
for illustrative purposes (not suggesting that that looks good).
\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}
\begin{document}
\begin{align*}
X &= AAA + BBB + CCC \\
&= \makebox[\widthof{$AAA$}]{$a$}
+ \makebox[\widthof{$BBB$}]{$b$}
+ \makebox[\widthof{$CCC$}]{$c$}
\end{align*}
\begin{align*}
X &= AAA + BBB + CCC \\
&= \makebox[\widthof{$AAA$}][l]{$a$}
+ \makebox[\widthof{$BBB$}][l]{$b$}
+ \makebox[\widthof{$CCC$}][r]{$c$}
\end{align*}
\end{document}