views:

83

answers:

4

I always like my figures to be placed in between text as opposed to the top or bottom of the page. I also like to talk about the figure before it is shown. So I am trying to have something like this:

By looking at Figure~\ref{fig:VCO} you can see that blah blah blah.

\begin{figure}[h]
\caption{VCO test circuit}\label{fig:VCO}
\begin{center}
\includegraphics[width=0.9\columnwidth]{figures/VCO_circuit.eps}
\end{center}
\end{figure}

This doesn't seem to work because it I guess it is referencing something that hasn't occurred yet? Does anyone have some simple solution? I am still very new to LaTeX.

A: 

Actually it seems like it is now working, I don't know what was going on!

Adam
It worked a second time because it was able to use the label data (stored in a separate file, IIRC) left from the first pass. For labels to work, you always need to run LaTeX twice. Also - next time, try asking on http://tex.stackexchange.com :)
Matt Ball
As a rule of thumb you can run latex or pdflatex command twice. It will get all your reference correct.
Hemang
+1  A: 

It failed the first time because labeling and referencing are a two-pass process. The first time you processed your latex, all the labels were being indexed so the ref failed. The second time around, since the labels had been indexed the ref knew what it was actually referencing.

jamessan
+3  A: 

Generally LaTeX needs at least two passes to resolve all its references, the first time to write them to an auxiliary file and the second time to put them into the final ps/pdf/dvi file. So it does not matter where the reference is.

A third pass will be needed, for example, if your document has a long table-of-contents which will screw up page numbers.

John Smith
+1 for answer-ifying [my comment](http://stackoverflow.com/questions/3916945/how-do-i-ref-a-figure-in-latex-before-it-occurs/3916960#3916960) more clearly than I could state it. The coffee hasn't kicked in yet, and it's been too long since I've actually used LaTeX.
Matt Ball
A: 

I would add that latexmk (link) has proven invaluable to me over the years. This is a LaTeX "build" script written in Perl that is designed to compile .tex source files the right number of times. It parses the output from the latex command and performs dependency checking to ensure that the output document is kept up-to-date with the minimum number of passes. It can also deal with BibTeX bibliography files. Generally speaking, I invoke latexmk from either an Ant or GNU Make makefile and treat it just like I'm compiling C++ code, for example.

Richard Cook