Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
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. –  canaaerus Feb 10 at 23:40
add comment

4 Answers 4

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.

share|improve this answer
2  
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. –  tohecz Feb 11 at 0:03
    
@tohecz Excellent point, and I see egreg has covered this in his answer. –  Torbjørn T. Feb 11 at 8:19
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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     &   
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.