[Tex/LaTex] I get double question marks when referring to labels inside figures

cross-referencing

I have some charts embedded in figures, and I want to be able to refer to them easily using the "Figure x" notation. I'm doing it like this (in this order):

\documentclass[12pt,letterpaper]{article}

...

\section*{Results}
...we performed a linear regression to obtain a standard curve 
(Figure~\ref{0:stdcurve})....

\pagebreak
\section*{Results (Graphs)}
\subsection*{Construction of Standard Graph for PNP}
\begin{figure}[h]   % Figure 1
    \centering
    \includegraphics[scale=1]{kinematics-res/graph0-1}
    \caption{The standard curve for PNP.}
    \label{0:stdcurve}
\end{figure}

However, instead of getting the output "…to obtain a standard curve (Figure 1)…", I just get "…to obtain a standard curve (Figure ??)…"

I also noticed that the PDFLaTeX compiler is generating warnings saying that it couldn't find the reference of the name 0:stdcurve. Why am I getting these warnings?

Best Answer

You need to run LaTeX twice. The first time it figures out the reference numbers. On the second pass it fills in the reference numbers.

The following generates ...standard curve (Figure {??}) upon the first pass, but generates ...standard curve (Figure 1)... upon the second pass:

\documentclass[12pt,letterpaper]{article}
\usepackage[demo]{graphicx} 

\begin{document}
\section*{Results}
...we performed a linear regression to obtain a standard curve 
(Figure~\ref{0:stdcurve})....

\pagebreak
\section*{Results (Graphs)}
\subsection*{Construction of Standard Graph for PNP}
\begin{figure}[h]   % Figure 1
    \centering
    \includegraphics[scale=1]{kinematics-res/graph0-1}
    \caption{The standard curve for PNP.}
    \label{0:stdcurve}
\end{figure}
\end{document}
Related Question