# Reference to a figure uses the section's number

One of my sections seems to be using the section number rather than the appropriate figure number for \ref's that point to figures. (Theorems and the like work fine.) As far as I can tell, there's nothing differentiating the problematic section from the other sections, but there must be as the problem doesn't go away when I compile that section on its own. Any ideas?

Edit: an example of a broken figure. (Every figure in the section is broken.)

\begin{example}
Figure~\ref{fig: hasse} depicts ...
\begin{figure}[htbp]\label{fig: hasse}
\begin{center}
\begin{tikzpicture}
\tikzstyle{every node}=[draw,circle,fill=black,minimum size=4pt,
inner sep=0pt]
[bunch of lines for the picture]
\end{tikzpicture}
\caption{Hasse diagram}
\end{center}
\end{figure}
\end{example}

This particular instance had the figure inside the example, but that doesn't make a difference.

-
Perhaps you did not use \caption before \label in that figure environment. Please show the code, so we don't have to guess. – Stefan Kottwitz Jun 1 '11 at 21:31
To clarify, it's an problem throughout the section, not just on one figure (only the one broken section, though). – hoyland Jun 1 '11 at 21:41
Do as Stefan has suggested: place the \label command after the corresponding \caption command (same remark applies to all floating environments). Instead of the center environment you could use the \centering command right after \begin{figure}[htbp]; the environment adds extra vertical space which (in most cases) is undesired – Gonzalo Medina Jun 1 '11 at 21:44

Move \label{fig: hasse} after \caption{Hasse diagram} since \caption has to come before \label. This applies to figures and tables in general. I would not use spaces in label names. Also note Gonzalos comment regarding \centering.

\begin{example}
Figure~\ref{fig:hasse} depicts ...
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\tikzstyle{every node}=[draw,circle,fill=black,minimum size=4pt,
inner sep=0pt]
[bunch of lines for the picture]
\end{tikzpicture}
\caption{Hasse diagram}
\label{fig:hasse}
\end{figure}
\end{example}
-
Thanks, I completely failed to parse your original comment correctly. The single section thing was a red herring--I was the one who did the figures in that section. Someone else did the others. – hoyland Jun 3 '11 at 12:36
What a simple solution to a problem that was driving me crazy! – Jus12 Nov 28 '15 at 7:31