19

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.

Adam
  • 191
  • 1
  • 1
  • 3

4 Answers4

21

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
  • 12,491
  • 18
  • 65
  • 111
  • 1
    +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 Oct 12 '10 at 16:42
  • How irrational is a compiler that requires three manual passes to produce the end product? – Eduardo Pignatelli Apr 28 '23 at 09:05
3

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
  • 41,569
  • 8
  • 85
  • 85
2

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
  • 32,523
  • 5
  • 46
  • 71
  • even better, I launch it with the `-pvc` flag when I start working and it shows a viewer with the result, updating it automatically every time a file is modified – Ciprian Tomoiagă Apr 23 '16 at 18:10
1

I had same problem and I found this solution:

\graphicspath{{images/}}
\DeclareGraphicsExtensions{.jpg}

\makeatletter
\newenvironment{tablehere}
  {\def\@captype{table}}
  {}

\newenvironment{figurehere}
  {\def\@captype{figure}}
  {}
\makeatother

\begin{figurehere}
\includegraphics[height=5cm]{2-14aGa-Sur.jpg}
\caption{Hliněná destička s mapou severu Mezopotámie}
\label{fig:Ga-Sur}
\end{figurehere}

\graphicspath{{images/}} is there to declare your path to your pictures

\DeclareGraphicsExtensions{.jpg} is there for declare picture extension (multiple can be with comma (I think ;-))

\makeatletter
\newenvironment{tablehere}
  {\def\@captype{table}}
  {}

\newenvironment{figurehere}
  {\def\@captype{figure}}
  {}
\makeatother

is there for precise determination of position here

\begin{figurehere}
\includegraphics[height=5cm]{2-14aGa-Sur.jpg}
\caption{Hliněná destička s mapou severu Mezopotámie}
\label{fig:Ga-Sur}
\end{figurehere}

there is your picture with height specified and caption and label with it...

I hope it will help you ;-).

Pavel
  • 11
  • 1