# [Tex/LaTex] Reference to a figure uses the section’s number

cross-referencingfloatsnumbering

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.

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}