4

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}

    \begin{equation}
    x = 2
    \end{equation}

    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?

2 Answers2

6

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}

    \begin{equation}
    x = 2
    \end{equation}

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

\end{document}
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
5

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}

    \begin{equation}
    x = 2
    \end{equation}

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

\end{document}
  • 1
    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