109

I've seen several answers that use the double ampersand, but I can't figure out exactly what it does.

I tried this out:

\begin{align*}
\frac{3x + y}{7} &= 9   & \text{given}   \\
3x + y &= 63            & \text{multiply by 7}   \\
3x &= 63 - y            & \text{subtract y}   \\
x &= 21 - \frac{y}{3}   & \text{divide by 3}   \\
\end{align*}

\begin{align*}
\frac{3x + y}{7} &= 9  && \text{given}   \\
3x + y &= 63           && \text{multiply by 7}   \\
3x &= 63 - y           && \text{subtract y}   \\
x &= 21 - \frac{y}{3}  && \text{divide by 3}   \\
\end{align*}

one & vs double && alignment

...and it looks like the only difference is right vs. left justification. But when I throw in this:

\begin{align*}
\frac{3x + y}{7} &&= 9  && \text{given}   \\
3x + y &&= 63           && \text{multiply by 7}   \\
3x &&= 63 - y           && \text{subtract y}   \\
x &&= 21 - \frac{y}{3}  && \text{divide by 3}   \\
\end{align*}

more than one && in one line

that goes out the window. What exactly does && do in LaTeX? Why does having a single && in a row make the last column left justified, but having two &&'s make it right justified? How do & and && differ?

1
  • 2
    In addition to Torbjørns excellent explanation one could say that the odd numbered ampersands are used to indicate alignment points and the even numbered ones separate multiple equations / columns, in each of which alignment occurs seperatly.
    – bodo
    Commented Feb 10, 2014 at 23:40

4 Answers 4

138

An align is a table-like structure, and & is a column separator. The thing is that the columns in an align are rlrlrlrlrl..., that is, every other column is right aligned and left aligned.

So, in

a &= b

the a is in a right aligned column, while =b is left aligned. When you do

a &= b & text

text will be in a right aligned column, but if you do

a &= b && text

text will be in a left aligned column, as you basically just add an empty column between =b and text.

Finally, as egreg points out in his answer and tohecz in his comment, note that amsmath will insert some stretchable space between each rl column pair, to distribute them across the width of the text block. This causes the effect seen in your last example.

5
  • 6
    As canaaerus points out, it's important that LaTeX inserts a stretchable space after each pair of rl, which creates the strange behaviour of OP's last example.
    – yo'
    Commented Feb 11, 2014 at 0:03
  • @tohecz Excellent point, and I see egreg has covered this in his answer. Commented Feb 11, 2014 at 8:19
  • Just awesome! I always play around with the align env. until its ok, but you solved the mystery! I am one of those people who are to stupid to RTFM...
    – jjstcool
    Commented Jun 14, 2017 at 20:44
  • 1
    Thanks for this answer! I was actually searching for this when using \begin{aligned} and I think it applies to that as well. But I cannot find anything about this in the amsmath document: texdoc.net/texmf-dist/doc/latex/amsmath/amsldoc.pdf Is there some reference explaining these "defaults" somewhere?
    – Alexandros
    Commented Apr 6, 2020 at 13:03
  • @Alexandros The same thing applies to aligned I believe, except for the extra space between each column pair. I'm not really sure what kind of defaults you mean. Commented Apr 6, 2020 at 13:09
39

Needed to say (an that's something the other answers miss a bit), && is nothing more and nothing less then & <no code here> &, i.e., it is just two tab column alignment points &s in a row.

It's not like dollars, where $ $ and $$ is an important difference: & & and && behave exactly the same way.

27

In general, & is the cell separator in tabulars and similar constructions. TeX computes the column widths dynamically, although it's possible to fix a column width. A double & has no special meaning: a single & means “go to the next cell of the alignment”, so && means “the next cell is empty, go to the following one”.

A generic tabular should be thought as a set of cells organized by rows and columns; the alignment is determined column by column (but can be overridden for single cells, in some cases).

The most common alignments are obtained with tabular or array (the difference is that the latter must go in math mode and the cells are typeset as math formulas). In tabular one must specify the column alignments, with input such as

\begin{tabular}{rcl}

which means “three columns, one right aligned, one centered, one left aligned”. Actually this adds some space next on either side of each column, so really we're specifying

<space><right alignment><space><space><center alignment><space><space><left alignment><space>

The space is fixed (\tabcolsep), but this can be modified in various ways.

With align the same idea applies, but the number of columns is unspecified; rather the pattern

<right alignment><left alignment><dynamic space>

is repeated as much as necessary. The <dynamic space> is not added at the end. So an input such as

\begin{align*}
\frac{3x + y}{7} &= 9                && \text{given} \\
3x + y           &= 63               && \text{multiply by 7} \\
3x               &= 63 - y           && \text{subtract y} \\
x                &= 21 - \frac{y}{3} && \text{divide by 3} \\
\end{align*}

which has a maximum of three & in the rows, builds an alignment according to the scheme

<right alignment><left alignment><dynamic space><right alignment><left alignment>

No space is added between the r and the l column in each pair (but special precautions are taken so that the = is correctly spaced.

An empty cell is reserved no space; for each column, the widest cell determines the reserved space; so in that alignment the third column occupies no space because all the cells in it are empty.

The “dynamic space” is determined based on the width of the columns, so as to avoid overfull lines as much as possible.

In your first example, the \text{...} entries end up in the third column, which is right aligned; in the above example, instead, they belong to the fourth column, which is left aligned.

In your third example, the cells starting with = belong to the third column, while the \text{...} ones are in the fifth: the alignment is (in abbreviated form)

<right><left><dynspace><right><left><dynspace><right><left>

where the second, fourth and sixth columns all have empty cells.

2

Inside align the first & usually comes before the sign and the other & is to change the column.

1st column left side &= 1st column right side   &    2nd column left side &= 2nd column right side     &   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .