83
Please see figure \ref{loginMock}.

\begin{figure}[H]
    \label{loginMock}
    \centering
    \includegraphics[width=7cm]{loginIdea}
    \caption{Landing/Login Page Example}
\end{figure}

I am using TexShop and the caption package, and tried compiling twice, but still ?? shows up.

The warning I'm getting in the console is:

Package caption Warning: \label without proper \caption on input line 29.
See the caption package documentation for explanation.


LaTeX Warning: Reference `loginMock' on page 1 undefined on input line 24.

thanks!

0

1 Answer 1

148

The \label should always be after \caption:

Please see figure \ref{loginMock}.

\begin{figure}[H]
    \centering
    \includegraphics[width=7cm]{loginIdea}
    \caption{Landing/Login Page Example}
    \label{loginMock}
\end{figure}

\label enables one to cross-reference a numbered "item"; the "item" can be a sectioning header, a figure, a table, or something else still. To know which numbered item to link to, \label consults a flag -- let's call it "the name of the most recently incremented counter variable" -- that is set by the low-level \refstepcounter macro. In the case of figure and table environments, the item's counter variables are incremented (via a call to \refstepcounter) whenever a \caption directive is issued.

So if you put \label before \caption, LaTeX cannot link the label to the counter variable (here: figure) that you have in mind. Instead, LaTeX links the label to whichever counter was incremented most recently via \refstepcounter. And, if no such variable was incremented previously in the document, LaTeX -- or, more precisely, the caption package, which you've loaded -- prints the warning message that you report.

1
  • I had always thought \label only needed to be the last entry in a figure, but I was caught out with a \begin{center} and \end{center} pair. Thanks.
    – user4417
    Sep 7 at 16:49

Not the answer you're looking for? Browse other questions tagged .