# Multiple alignment

In the following piece of code

\begin{align*}
[x \mapsto s]x &= s \\
[x \mapsto s]y &= y \qquad \text{als } y\neq x \\
[x \mapsto s](\la{y}t_1) &= \la{y}[x \mapsto s]t_1 \qquad \text{als } y \neq x \text{ en   } y \not \in FV(s) \\
[x \mapsto s](t_1 \; t_2)&= ([x \mapsto s]t_1)\;([x \mapsto s]t_2)
\end{align*}


I am currently only aligning on the = sign. Is it however also possible to align on more than one place in the environment? I would also like the \text to be aligned, as wel as the begining of each new line.

Multiple alignment points with no gap between expressions is obtained using the alignat environment from amsmath. The following MWE illustrates that:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignat*}{3}
&[x \mapsto s]x &&= s && \\
&[x \mapsto s]y &&= y \qquad &&\text{als } y\neq x \\
&[x \mapsto s](\lambda(y)t_1) &&= \lambda(y)[x \mapsto s]t_1 \qquad &&\text{als } y \neq x \text{ en   } y \not \in FV(s) \\
&[x \mapsto s](t_1 \; t_2)&&= ([x \mapsto s]t_1)\;([x \mapsto s]t_2) &&
\end{alignat*}

\end{document}


I've taken the liberty to convert the unknown \la{<arg>} macro to \lambda(<arg>).

Consider reading Herbert's mathmode document. It illustrates the various "alignment environments" of amsmath clearly. Specifically, see section 25 align environments, p 43 onward.

• great! will give it a read, also my apologies for the unknown macro, you converted it correctly,
– codd
May 20 '12 at 14:35
• One doesn't even need alignat: the simple align can do the same, but it adds spacing as it thinks correct, which might not be what the user wants. May 20 '12 at 14:37
• egreg: could you elaborate? Because spacing would be nice, I currently forced it using \qquad...
– codd
May 20 '12 at 14:38
• @codd: See @_barbarabeeton's answer. May 20 '12 at 17:31
• @Servaes: Thanks. The mathmode stub on CTAN puts the "package" down as obsolete (hence the link change). Oct 13 '16 at 12:05

using just align would be done like this:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
[x \mapsto s]x &= s \\
[x \mapsto s]y &= y &&\text{als } y\neq x \\
[x \mapsto s](\lambda(y)t_1) &= \lambda(y)[x \mapsto s]t_1 &&\text{als } y \neq x \text{ en   } y \not \in FV(s) \\
[x \mapsto s](t_1 \; t_2) &= (x \mapsto s]t_1)\;([x \mapsto s]t_2)
\end{align*}
\end{document}


this gives the following result:

• when I try this, significant white space is inserted in front of the && character. Any idea why? Mar 4 '20 at 17:36
• @RylanSchaeffer -- align assumes "columns" of equations, so it separates them by a wider space to make them distinct. The answer using alignat is probably more appropriate for the situation described in this question. Mar 4 '20 at 17:43

The above suggestions, e.g., alignat, all produce a reference number for each line. If you need to reference the entire block by one number, use alignedat in an equation environment:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{alignedat}{3} &[x \mapsto s]x &&= s && \\ &[x \mapsto s]y &&= y \qquad &&\text{als } y\neq x \\ &[x \mapsto s](\lambda(y)t_1) &&= \lambda(y)[x \mapsto s]t_1 \qquad &&\text{als } y \neq x \text{ en } y \not \in FV(s) \\ &[x \mapsto s](t_1 \; t_2)&&= ([x \mapsto s]t_1)\;([x \mapsto s]t_2) && \end{alignedat}