1

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

0
2

I suggested you use an aligned for the internal alignment:

Sample output

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

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

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}

enter image description here

1

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} 

enter image description here

0

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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