# Why does aligning equations not work here?

\documentclass{minimal}

\usepackage{amsmath}
\newcommand*{\op}[1]{\operatorname{#1}}

\begin{document}

\begin{align*}
\noalign{$\quad \op{f} * \op{r} = \op{c}_{\op{f}*\op{r}} (x_1,...,x_k) = (\op{f}(a_1,...,a_k), \op{r}(b_1,...,b_k))$}
&\text{if } x_i=(x^{\op{f}}_i,x^{\op{r}}_i), &\text{then } a_i=x^{\op{f}}_i \in \mathcal{S}, b_i=x^{\op{r}}_i \in (\mathcal{A}^*)^*, &1 \leq i \leq k\\
&\text{if } x_i \in \mathcal{A}^*, &\text{then } a_i=b_i=x_i, &1 \leq i \leq k
\end{align*}

\end{document}


Obviously, "then" should be aligned, too. What am I doing wrong?

I also tried it with aligned and {alignat*}{2}, but it's not correct there either.

-
use {alignat*}{3} and change &\text{then } to &&\text{then} – mythealias Nov 21 '12 at 11:47
I believe that \op should not expand to \operatorname, but rather to \mathrm. Why do you want function names to be upright? Also, never use the minimal class for MWEs, prefer article. – egreg Nov 21 '12 at 11:57
@egreg Hmm, somewhere I read that functions are upright and variables italic. As \sin etc. If it's not like that, then what's the use having \operatorname? – neo Nov 21 '12 at 12:07
Those particular function names are typeset upright and, in general multiletter function names. Not "normal" functions. \operatorname adds spacings that are usually not wanted for single letter function names. – egreg Nov 21 '12 at 12:32
I think I know what you mean by "normal" functions: every function that is not globally defined in a document but rather used as a variable, like f \in F (where F is a set of functions) or in my case also f * r as f and r are just arguments in this scope. – neo Nov 21 '12 at 13:47

You need to use a double &&:

The reason is that the align and alignat environment both provide pairs of rl aligned equations. So if you want a left aligned point you need to skip over the right aligned point.

If you want to control the spacing in between the columns, then use the alignat in which case you need to manually add the space. Here I have added a \quad for the spacing spacing:

As requested in the comments, here is an alternate use of align which ensures that the start of the last two lines is aligned with the first = of the first line.

## Notes:

• A \phantom{{}={}} was used to ensure that the last two lines are aligned to the text to the right of the =. The additional {} in the \phantom is used to ensure proper spacing is applied around the =. We could also have use \hphantom{} instead, but both will yield identical result in this case.
• rlap was used so that the right hand sides is not going to have an effect on the alignment of the subsequent rows.

## Code:

\documentclass{article}

\usepackage{amsmath}
\newcommand*{\op}[1]{\operatorname{#1}}

\begin{document}
\noindent
Using \verb|align|:
\begin{align*}
\noalign{$\quad \op{f} * \op{r} = \op{c}_{\op{f}*\op{r}} (x_1,...,x_k) = (\op{f}(a_1,...,a_k), \op{r}(b_1,...,b_k))$}
&\text{if } x_i=(x^{\op{f}}_i,x^{\op{r}}_i), &&\text{then } a_i=x^{\op{f}}_i \in \mathcal{S}, b_i=x^{\op{r}}_i \in (\mathcal{A}^*)^*, &&1 \leq i \leq k\\
&\text{if } x_i \in \mathcal{A}^*, &&\text{then } a_i=b_i=x_i, &&1 \leq i \leq k
\end{align*}
Using \verb|alignat|:
\begin{alignat*}{3}
\noalign{$\quad \op{f} * \op{r} = \op{c}_{\op{f}*\op{r}} (x_1,...,x_k) = (\op{f}(a_1,...,a_k), \op{r}(b_1,...,b_k))$}
&\text{if } x_i=(x^{\op{f}}_i,x^{\op{r}}_i), &&\quad\text{then } a_i=x^{\op{f}}_i \in \mathcal{S}, b_i=x^{\op{r}}_i \in (\mathcal{A}^*)^*, &&\quad 1 \leq i \leq k\\
&\text{if } x_i \in \mathcal{A}^*, &&\quad\text{then } a_i=b_i=x_i, &&\quad 1 \leq i \leq k
\end{alignat*}
\hrule\medskip\noindent
Alternate alignment with \verb|align|:
\begin{align*}
\op{f} * \op{r} &= \op{c}_{\op{f}*\op{r}} (x_1,...,x_k) \rlap{${}= (\op{f}(a_1,...,a_k), \op{r}(b_1,...,b_k))$}\\
&\phantom{{}={}}\text{if } x_i=(x^{\op{f}}_i,x^{\op{r}}_i), &&\text{then } a_i=x^{\op{f}}_i \in \mathcal{S}, b_i=x^{\op{r}}_i \in (\mathcal{A}^*)^*, &&1 \leq i \leq k\\
&\phantom{{}={}}\text{if } x_i \in \mathcal{A}^*, &&\text{then } a_i=b_i=x_i, &&1 \leq i \leq k
\end{align*}
\end{document}

-
I see, although I'd rather not use \quads. Is it possible to use align with && so that the start of the second and third line is aligned to the first = of the first line (without aligning the rest of the first line)? – neo Nov 21 '12 at 12:04
@neo: Have updated solution to provide an alternate alignment with align. – Peter Grill Nov 21 '12 at 19:46

Peter Grill has already answered your basic problem with the number of ampersands. However, I would suggest a different approach of introducing an aligned environment to contain the second and third lines. This left hand side of this can then be lined up with the first line using an enclosing align environment. Do this to the right of the equals sign is accomplished by a = {}& to correct correct spacing around that sign.

\documentclass{article}

\usepackage{amsmath}

\begin{document}

Alignment to left of equals:
\begin{align*}
f * r &=  c_{f*r} (x_1,...,x_k) = (f(a_1,...,a_k), r(b_1,...,b_k))\\
&
\begin{aligned}
&\text{if } x_i=(x^f_i,x^r_i), &&\text{then } a_i=x^f_i
\in \mathcal{S}, b_i=x^r_i \in (\mathcal{A}^*)^*,
&1 \leq i \leq k,\\
&\text{if } x_i \in \mathcal{A}^*, &&\text{then } a_i=b_i=x_i,
&1 \leq i \leq k.
\end{aligned}
\end{align*}

Alignment to right of equals:
\begin{align*}
f * r = {}&  c_{f*r} (x_1,...,x_k) = (f(a_1,...,a_k), r(b_1,...,b_k))\\
&
\begin{aligned}
&\text{if } x_i=(x^f_i,x^r_i), &&\text{then } a_i=x^f_i
\in \mathcal{S}, b_i=x^r_i \in (\mathcal{A}^*)^*,
&1 \leq i \leq k,\\
&\text{if } x_i \in \mathcal{A}^*, &&\text{then } a_i=b_i=x_i,
&1 \leq i \leq k.
\end{aligned}
\end{align*}

\end{document}


I have taken advantage of the comments to the question to remove the \op commands.

-
I accepted the other answer as it answered the original question already, but +1 for your answer, I really like it. No hackery and very logical. – neo Nov 22 '12 at 20:11