7

I have the following code in \documentclass{beamer},

\documentclass{beamer}

\begin{document}
\begin{frame}
  \texttt{align} environment:
  \begin{align}
  \begin{bmatrix}
    x\\y\\z
  \end{bmatrix}&=
                 \begin{bmatrix}
                   1&&\\&2&\\&&3
                 \end{bmatrix}
                 \begin{bmatrix}
                   1\\2\\3
                 \end{bmatrix} \\
  &=
  \label{eq:4}
                 \begin{bmatrix}
                   1&&\\&2&\\&&3
                 \end{bmatrix}
                 \begin{bmatrix}
                   d\\e\\f
                 \end{bmatrix}\\
  \label{eq:1}
  a&=b
\end{align}
\texttt{equation} environment:
\begin{equation}
  \label{eq:5}
  a^{2}+b^{2}=c^{2}
\end{equation}
\end{frame}
\end{document}

which gives the following slide.

Enter image description here

And we can see that the last equation number does not line up. I did not have such a problem if I used \documentclass{article} instead.

Why is this happening, and how can I fix this?

  • 1
    If you add \tag{a\rlap{\smash{\rule[-10cm]{0.4pt}{12cm}}}} to the first row in the align, the problem is easily seen. – daleif Jan 9 '18 at 8:30
  • Theory: in beamer, perhaps equation is redefined to be gather, because gather shows the same problem. Might want to add gather as an example as well. – daleif Jan 9 '18 at 8:32
  • Further experiment, it is something inside the beamer frame env, if you redefine frame to do nothing (\renewenvironment) then the placement is correct. We probably need some of the beamer people to have a look at this. – daleif Jan 9 '18 at 8:37
  • 1
    @daleif I noticed just now that not only the label, the two matrices does not align either. btw, glad to know the trick to show this. – davyjones Jan 9 '18 at 8:40
  • Yes, now you mention it. I'm currently updating my TeXLive to see if there are any updates that I have missed. The (r/l)lap+smash+rule trick is rather useful. – daleif Jan 9 '18 at 8:43
9

After a bit of messing around, the issue seems to be a bad \label placement.

               \end{bmatrix} \\
&=
\label{eq:4} %<----
             \begin{bmatrix}

Note that the marked label is after &=, the whatsit probably ends up confusing the math spacing. Moving the \label up as the first thing on this line, removes the problem.

The solution is to start or end the row with \label, don't add it the middle of the formula. For the sniplet above use

               \end{bmatrix} \\
\label{eq:4} %<----
&=
             \begin{bmatrix}

I have no idea why this causes the equation numbers to be placed misaligned.

  • excuse me, could you pls provide a complete code sample so that I can test it? currently any \label inside align will mess up the alignment for me. thanks~ – davyjones Jan 9 '18 at 9:02
  • 2
    Oh, I had to put \label{eq:4} above &= to make everything (matrices + equation numbers) align – davyjones Jan 9 '18 at 9:06
  • 1
    Thanks, I see where I did wrong in my original code. Another questions is that if I add a \label{eq:xx} above the first equations (below \begin{align}), the misalignment reappears. This time it's just the numbering, not the matrices. How can I fix that? – davyjones Jan 9 '18 at 9:14
  • 1
    sure, I'll try it out and post it soon. I think this new question is the real question I originally want to ask. I'll do it more carefully next time. Thanks! – davyjones Jan 9 '18 at 9:17
  • 2
    @davyjones seems {\label{...}} helps... – daleif Jan 9 '18 at 9:56
4

I think the problem is caused by the bmatrix environment. Use {\begin{bmatrix}...\end{bmatrix}}! Try this code:

\documentclass{beamer}
\begin{document}
\begin{frame}
  \texttt{align} environment:
\begin{align}
  {\begin{bmatrix}
    x\\y\\z
  \end{bmatrix}}&=
                 {\begin{bmatrix}
                   1&&\\&2&\\&&3
                 \end{bmatrix}}
                 {\begin{bmatrix}
                   1\\2\\3
                 \end{bmatrix}}\label{eq:1}\\
  &=
                 {\begin{bmatrix}
                   1&&\\&2&\\&&3
                 \end{bmatrix}}
                 {\begin{bmatrix}
                   d\\e\\f
                 \end{bmatrix}}\label{eq:2}\\
  a&=b\label{eq:3}
\end{align}
\texttt{equation} environment:
\begin{equation}\label{eq:4}
  a^{2}+b^{2}=c^{2}
\end{equation}
\end{frame}
\end{document}

enter image description here

  • yes, I saw something similar in the chatroom, this is really a unconventional strike for bmatrix fans. I'll post another question to attract beamer maintainers' attention as suggested. – davyjones Jan 9 '18 at 10:54

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.