An align environment question

Currently i have something like this:

  $A = B$
\begin{alignat*}{2}
AAA = BBBB &=  CCCCCCCC  &&= DDDD \\
AAA = BBBB &=  \qquad CCC  &&= DDDD \\
\end{alignat*}


In would like to have almost the same effect without the vertical spacing between the first and second equation, so is there a way to push first equation inside the aligned environment and keeping it centered?

Also, is there a better way to center the "CCC" in the third equation?

• The spacing above and below of those environments is controlled by the lengths \abovedisplayskip and \belowdisplayskip. Use a group around your math stuff and set the lengths to appropiate values then. For the centering I have no clue
– user31729
Jul 17, 2015 at 7:51

Just amsmath

You can use alignedat inside a gather*.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather*}
A = B \\
\begin{alignedat}{2}
AAA = BBBB &=  CCCCCCCC  &&= DDDD \\
AAA = BBBB &=  \qquad CCC  &&= DDDD \\
\end{alignedat}
\end{gather*}
\end{document}


Centering using the calc package

One possible way of centering CCC is to use \widthof from the calc package to calculate the width of CCCCCCCC, and set CCC centered in a box of this width.

\documentclass{article}
\usepackage{amsmath,calc}
\begin{document}
\begin{gather*}
A = B \\
\begin{alignedat}{2}
AAA = BBBB &=  CCCCCCCC  &&= DDDD \\
AAA = BBBB &=   \makebox[\widthof{$\displaystyle CCCCCCCC$}][c]{$\displaystyle CCC$}  &&= DDDD \\
\end{alignedat}
\end{gather*}
\end{document}


Here I add the equals sign to the array specification instead of typing them explicitly. To get the better spacing an empty group is added on either side, i.e. @{ {}={} }.

\jot is the default spacing between lines in multiline math environments from amsmath.

\documentclass{article}
\usepackage{mathtools}

\begin{document}
$\begin{array}{*{3}{@{} c@{ {}={} }} c} \multicolumn{4}{c}{A=B}\\[\jot] AAA & BBBB & CCCCCCCC & DDDD \\[\jot] AAA & BBBB & CCC & DDDD \\[\jot] \end{array}$
\end{document}


Just an idea: use array. Intercolumn space is not nice, but it can be adjusted.

\documentclass{article}
\usepackage{mathtools}

\begin{document}
$\begin{array}{*{7}{c}} \multicolumn{7}{c}{\begin{array}{ccc}A&=&B\end{array}}\\ AAA & = & BBBB & = & CCCCCCCC &=& DDDD \\ AAA & = & BBBB &= & CCC &= &DDDD \\ \end{array}$
\end{document}


EDIT: Still not perfect, but next code looks nicer:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
$\setlength{\arraycolsep}{1pt} \begin{array}{*{4}{c}} \multicolumn{4}{c}{A=B}\\ AAA = & BBBB = & CCCCCCCC &= DDDD \\ AAA = & BBBB = & CCC &= DDDD \\ \end{array}$
\end{document}