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.

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!

share|improve this question

migrated from stackoverflow.com Oct 16 '12 at 6:26

This question came from our site for professional and enthusiast programmers.

marked as duplicate by David Carlisle, Heiko Oberdiek, lockstep, percusse, cgnieder Oct 16 '12 at 9:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Try to put the \label after the \includegraphics. –  Dror Oct 16 '12 at 8:00
    
@Dror: thanks, but it still doesn't work... –  alittleboy Oct 16 '12 at 16:57

Browse other questions tagged or ask your own question.