# Equation numbers do not align to rightmost in beamer

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:
$$\label{eq:5} a^{2}+b^{2}=c^{2}$$
\end{frame}
\end{document}


which gives the following slide.

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?

• If you add \tag{a\rlap{\smash{\rule[-10cm]{0.4pt}{12cm}}}} to the first row in the align, the problem is easily seen. Jan 9, 2018 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. Jan 9, 2018 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. Jan 9, 2018 at 8:37
• @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. Jan 9, 2018 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. Jan 9, 2018 at 8:43

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~ Jan 9, 2018 at 9:02
• Oh, I had to put \label{eq:4} above &= to make everything (matrices + equation numbers) align Jan 9, 2018 at 9:06
• 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? Jan 9, 2018 at 9:14
• 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! Jan 9, 2018 at 9:17
• @davyjones seems {\label{...}} helps... Jan 9, 2018 at 9:56

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:
$$\label{eq:4} a^{2}+b^{2}=c^{2}$$
\end{frame}
\end{document}


• 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. Jan 9, 2018 at 10:54