Possible Duplicate:
Why does an environment’s label have to appear after the caption?
Where to put the \label on a figure environment?
When using RStudio to write a .Rnw file, I find that when inserting a plot, the cross reference is not expected. For example, in section 5.3 I insert a plot using the following commands:
\begin{figure}[!htb]
\begin{center}\label{fig:testplot}
\includegraphics[scale=0.8]{testplot.pdf}
\caption{I'm caption}
\end{center}
\end{figure}
In the text, I write "In Figure~\ref{fig:testplot}" to reference this plot. However, after clicking Compile PDF, I find that what produced is "In Figure 5.3" --> it is the section number, not the desired figure number (it should print out Figure 4 since three figures already existed in the text). What went wrong?
Thank you very much!
\labelafter the\includegraphics. – Dror Oct 16 '12 at 08:00