Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
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
3  
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
add comment

1 Answer

up vote 9 down vote accepted

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}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.