# I can't figure out why my ref is displaying question marks instead of a figure number regarding a float [duplicate]

Please see figure \ref{loginMock}.

\begin{figure}[H]
\centering
\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!

• If you use \label before it the old label text is used instead, which leads to a wrong number. Always use \label after \caption and not before or in it. – user24094 Nov 24 '15 at 19:00

The \label should always be after \caption:

Please see figure \ref{loginMock}.

\begin{figure}[H]
\centering

\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.
• @Mico The only reason to revert the modifications is to earn the cleanup badge and I don't mind so I'm fine ;-)` – Romain Picot Nov 24 '15 at 8:15