[Tex/LaTex] Why does aligning equations not work here

align

\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}

enter image description here

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.

Best Answer

You need to use a double &&:

enter image description here

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:

enter image description here


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.

enter image description here

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}
Related Question