# Math mode align multiple lines with different number of columns

I have a problem with the align environment. I want to align three lines at the "=" sign and only the first two lines at an additional position. How can I do this without getting weird spacings? So far, my code produces strange gaps.

\documentclass[10pt,twocolumn,letterpaper]{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
Q(c) &= max_{k} & \prod_{t=1}^T \cdot p(t,c|k) \nonumber \\
&          & \cdot z(k) \nonumber \\
&= Q(z(c)) + p(t,c|z(k))
\end{align}
\end{document}


I'd like to have the alignment as displayed in the code: All lines should be aligned to the = in the first line and the first two rows should additionally be aligned at the product sign.

Thanks a lot for your help!

Alex

I suggested you use an aligned for the internal alignment:

\documentclass[10pt,twocolumn,letterpaper]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
Q(c) &= \max_{k}
\!\begin{aligned}[t]
& \prod_{t=1}^T \cdot p(t,c|k) \\
& \cdot z(k)
\end{aligned}
\nonumber\\
&= Q(z(c)) + p(t,c|z(k))
\end{align}

\end{document}


aligned is much like align but just for internal blocks of an equation. It takes an optional argument t or b to specify its vertical placement relative to the surrounding equation. The \! kills a small space that it is automatically inserted in front of aligned.

• That's exactly what I was looking for! Thanks a lot! – Alex Oct 14 '15 at 15:11

Or use alignat and \mathrlap:

\documentclass[10pt,twocolumn,letterpaper]{article}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{alignat}{2}
Q(c) &= max_{k}  &\prod_{t=1}^T &\cdot p(t,c|k) \nonumber \\
&           &&\cdot z(k) \nonumber \\
&= \mathrlap{Q(z(c)) + p(t,c|z(k))}
\end{alignat}


Like that?

\documentclass[10pt,twocolumn,letterpaper]{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
Q(c) &= \max_{k }\! \begin{aligned}[t] & \prod_{t=1}^T{} \cdot p(t,c|k) \nonumber \\
& \cdot z(k)\end{aligned} \nonumber \\
&= Q(z(c)) + p(t,c|z(k))
\end{align}

\end{document}


With \phantom

\documentclass[10pt,twocolumn,letterpaper]{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
Q(c) &= \max_{k}  \prod_{t=1}^T \cdot p(t,c|k) \nonumber \\
& \phantom{{}= \max_{k}}          \cdot z(k) \nonumber \\
&= Q(z(c)) + p(t,c|z(k))
\end{align}
\end{document}