# Inexplicable equation numbering in Beamer

Here is my code:

\documentclass{beamer}
\usepackage{amsfonts}
\usepackage{amsmath}

\begin{document}
\frame{\titlepage}

\begin{frame}
\begin{gather}\label{equation1}
a^2 + b^2 = c^2
\end{gather}
Consider \eqref{equation1}. This is fine.
\end{frame}

\begin{frame}
But then:
\begin{gather}\label{equation2}
x^2 + y^2 = z^2\nonumber\\
r + s + t
\end{gather}

$$x = 2$$

Equation (2) is referenced as \eqref{equation2}. Why???
\end{frame}

\end{document}


I do not understand why in the last line, \eqref(equation2) shows up as (3) despite clearly being designated as (2). How do I work around this in an efficient manner, particularly since I am going to have to code multiple slides with this sort of thing?

• You explicately said that the second equation will not get a number. This would confuse me as well. Place the label at the end of the gather block, not at the beginning. – Johannes_B Feb 12 '17 at 8:21
• Aside: Using gather (and align) environments for single-line displayed equations constitutes a form of typographic abuse. Use equation environments instead. See the posting What are the differences between , [, align, equation and displaymath for more information on this subject. – Mico Feb 12 '17 at 8:28
• Add your \label after the second equation of your gather environment. – Paul Gaborit Feb 12 '17 at 8:30
• I put the label just inside the \end{gather} tag. It does what I want now. But why was it messing up to begin with? Again, this was not a problem in regular documents. – Forklift17 Feb 12 '17 at 8:30
• @Phys251 - Are you sure about your claim that "this was not a problem in regular documents"? For instance, when I take your code, change beamer to article in the \documentclass instruction, and remove the frame-related instructions, the cross-reference to the second, mis-marked equation comes up blank, i.e, as "()" -- no equation number at all. I wouldn't call that "not a problem". – Mico Feb 12 '17 at 8:37

Amsmath environments align and gather are intended to typeset multiple equations, so they require putting one \label{whatever} per line you want to refer to.

What happens if you put \label{equation2} at the line which is marked by \nonumber (so, you don't want to number this equation) is that the label will pick up the previously stepped counter. In this case it's a frame number counter, so your (3) meant the frame number and not the equation number.

Moving he label \label{equation2} definition to the second equation in the gather environment helps.

\documentclass{beamer}
\usepackage{amsfonts}
\usepackage{amsmath}

\begin{document}
\frame{\titlepage}

\begin{frame}
\begin{gather}\label{equation1}
a^2 + b^2 = c^2
\end{gather}
Consider \eqref{equation1}. This is fine.
\end{frame}

\begin{frame}
But then:
\begin{gather}
x^2 + y^2 = z^2\nonumber\\
r + s + t\label{equation2}
\end{gather}

$$x = 2$$

Equation (2) is referenced as \eqref{equation2}. Why???
\end{frame}

\end{document}

• Good catch, identifying the fact that the unexpected number "3" refers to the frame number and not to the (later) equation number. – Mico Feb 12 '17 at 10:38

You have the \label in the wrong place: they need to come after the numbered item:

\documentclass{beamer}
\usepackage{amsfonts}
\usepackage{amsmath}

\begin{document}
\frame{\titlepage}

\begin{frame}
\begin{gather}
a^2 + b^2 = c^2\label{equation1}
\end{gather}
Consider \eqref{equation1}. This is fine.
\end{frame}

\begin{frame}
But then:
\begin{gather}
x^2 + y^2 = z^2\nonumber\\
r + s + t\label{equation2}
\end{gather}

$$x = 2$$

Equation~(2) is referenced as \eqref{equation2}. Why???
\end{frame}

\end{document}