4

I hope I'm not duplicating anything here...

My simple question is: what are the rules to align the various lines in an align environment?

For example - at first I thought that

\begin{align*}
a &= bbbbbbbbbbbbbb \\
c &= d
\end{align*}

would align the "=" at the center of the page, but that's not the case.

Then I tought that it would put the longer (first) equation in the middle of the page, but that's not the case either. In fact the previous code snippet would not put the "=" in the same position as

\begin{align*}
a &= bbbbbbbbbbbbbb \\
cc &= d
\end{align*}

(only difference is that there are two "c"'s now).

So what's the rule?

Giulio
  • 327
  • align is basically an array with columns right-left-right-left... (see this answer of mine for a description of aligned, which is similar). The resulting array will be centered on the line (unless of course fleqn is used). – campa May 28 '20 at 13:56

2 Answers2

3

The align environment does not do what you think it should.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor} % for the guide rule

\begin{document}

\noindent\smash{\makebox[\textwidth]{\hfill\color{black!20}\vrule depth \textheight\hfill}}

First example:
\begin{align*}
a &= bbbbbbbbbbbbbb \\
c &= d
\end{align*}
\makebox[\textwidth]{%
  \settowidth{\dimen0}{$\displaystyle a = bbbbbbbbbbbbbb$}%
  \hrulefill
  \smash{\makebox[\dimen0]{\color{red}\vrule height2cm\hrulefill\vrule height2cm}}%
  \hrulefill
}

Second example:
\begin{align*}
a &= bbbbbbbbbbbbbb \\
cc &= d
\end{align*}
\makebox[\textwidth]{%
  \settowidth{\dimen0}{$\displaystyle cc = bbbbbbbbbbbbbb$}%
  \hrulefill
  \smash{\makebox[\dimen0]{\color{red}\vrule height2cm\hrulefill\vrule height2cm}}%
  \hrulefill
}

\end{document}

Don't bother with the code for producing the rules, it's irrelevant for the explanation; I just use it for showing what align does.

enter image description here

The gray rule marks the exact longitudinal axis of the page. The red rules mark the bounds for the align environment. You see that, normally, the entire block is horizontally centered by taking into account the whole width.

This is valid for align with a single alignment point or not so wide equations. If the equation number is added, there's no adjustment, in general.

enter image description here

The picture has been obtained by changing align* into align. However, if the block is so wide as to be too near to the equation number, it will be moved to the left (or to the right if numbers are on the left).

There is no typographic reason for attempting to place the alignment point at the center of the page, especially if the “right-hand side” of the equation (what's after the alignment point, actually) is long. Let's make a simulation.

This is what you'd get by centering the equals signs on the page:

enter image description here

This is the standard placement:

enter image description here

It's not the position of the alignment point on the page that concerns us, but the relative position of the alignment points with respect to each other and the overall balance of the whole thing, including the text above and below the display.

Remember also that the simple fact you're displaying some equation in a block doesn't necessarily warrant align; it does if there are relations between the equations. A lot of times we see alignments at equals signs that are unnecessary and produce very unbalanced results. Remember that you can nest align in gather for cases where groups of equations in a display need alignment, but not all of them.

When there are more alignment points, align makes blocks of “right aligned/left aligned” columns and positions them by equally dividing the blank space remaining between the blocks.

egreg
  • 1,121,712
0

align's priority is to align the relation symbols preceded by & with each other. It then centers the box wrapping the entire contents of the environment. Something like the below.

screenshot

General tips: don't use \\ after the last line, and put the & before, and not after, the relation symbol. Otherwise see also What's the best way to align binary operators to the right of a relation symbol?.

You can find further infos in the amsmath User Guide, §3.

This question may also be of interest: align the '=' in separate equations always at the center of the page.

The code that generated the above is unnecessarily convoluted, but I'll still include it:

\documentclass{article}

\usepackage{amsmath, mathtools}
\usepackage{tikz}

\usepackage{empheq}
\usepackage[showframe]{geometry}

\begin{document}

\noindent\hspace*{\fill}\tikz[remember picture, overlay]{\draw[black!50] (0,-19) -- (0,3);}\hspace*{\fill}

\verb|align*| with markers
\begin{empheq}[box=\fbox]{align*}
\Aboxed{\text{who knows} &= a \hspace{5cm} a} \\
\Aboxed{a \hspace{6cm} a &= \text{some long math stuff}}
\end{empheq}

\verb|align*| without markers
\begin{empheq}[box=\fbox]{align*}
\Aboxed{\text{who knows} = a \hspace{5cm} a} \\
\Aboxed{a \hspace{6cm} a = \text{some long math stuff}}
\end{empheq}

\verb|gather*|
\begin{empheq}[box=\fbox]{gather*}
    \boxed{\text{who knows} = a \hspace{5cm} a} \\
    \boxed{a \hspace{6cm} a = \text{some long math stuff}}
\end{empheq}

\end{document}
steve
  • 2,154