[Tex/LaTex] References won’t resolve even after repeated compilation

captionscross-referencing

I have the following lines:

\begin{figure}[htbp]
\label{fig:sampleconfig}
\begin{center}
\begin{tikzpicture}[level distance=1.5cm, grow=down,
    every node/.style={minimum size=1cm,circle,thin,draw},
    edge from parent/.style={-latex, thin, draw}
]
\node {$A$}
    child {
        node {$CO_{1}$}
        child {node[rectangle,draw] {$CL_{1}$}}
    }
    child {
        node[circle,dotted,draw] {$\cdots$}
        child {node[rectangle,dotted,draw] {$\cdots$}}
    }
    child {
        node {$CO_{n}$}
        child {node[rectangle,draw] {$CL_{n}$}}
    }
;
\end{tikzpicture}
\caption{Sample configuration}
\end{center}
\end{figure}

In Figure ~\ref{fig:sampleconfig}, the node labelled $A$ is the root APPLICATION node.

No matter how many times I recompile the LaTeX file, I still get two question marks in place of "Figure 1," like so: "Figure ??."

Am I doing something incorrectly?

Thanks in advance for your help.

EDIT

In case it would help to solve the problem: I'm using MikTex 2.9 on Windows 7.

Best Answer

Put your label in the caption itself. i.e.

\caption{Sample configuration\label{fig:sampleconfig}}

It should work then. You can also place it after the caption as long as it is still in the figure environment. Figure labels do not behave correctly if they are placed before the caption.

Related Question