Graphics, Figures & TablesPreceeding References to following Figures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jomike
Posts: 5
Joined: Wed Nov 14, 2012 10:42 pm

Preceeding References to following Figures

Post by jomike »

Hello!

Just recently, I started using LaTeX. I have the following referencing problem.

If I place a reference for a figure (for the below example: \ref{fig: a figure}) or a table before this figure or table, then Latex only gives me the output "??".

This doesn't occur when I place the reference behind the figure/table. Here is a example code:

Code: Select all

\begin{figure}
\caption{a figure}
\label{a figure}
\includegraphics[scale=0.94]{figure.pdf}
\end{figure}
I'd be so glad if someone could help me out (I'm going mad with this problem)!


Greetings,
jomike

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Preceeding References to following Figures

Post by nlct »

Just make sure you run latex twice to ensure the references are up-to-date.

Code: Select all

\documentclass{article}

\usepackage{graphicx}

\begin{document}

Figure~\ref{fig:sample} is an example.

\begin{figure}
 \centering
 \includegraphics{test-image}
 \caption{Sample Figure}
 \label{fig:sample}
\end{figure}

\end{document}
Regards
Nicola Talbot
jomike
Posts: 5
Joined: Wed Nov 14, 2012 10:42 pm

Re: Preceeding References to following Figures

Post by jomike »

A little late, but: thanks Nicola, after applying your advice, it worked well!
Post Reply