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:

\caption{I'm caption}

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!

marked as duplicate by David Carlisle, Heiko Oberdiek, lockstep, percusse, clemens 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.

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

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

  • 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.