LaTeX examples: How to reference a figure or table

LaTeX table/figure FAQ: How do I reference a table or figure in a LaTeX document?

Being able to automatically reference a figure within a LaTeX document is a very cool thing. This referencing capability lets you easily give readers the exact number of a figure, or tell them what page number a figure is located on with the use of a few simple commands (\label, \ref, and \pageref). The same technique works for referencing other objects within a LaTeX document, including tables and equations.

Here’s the simple two-step process to use and reference figures in LaTeX documents.

Back to top

1) Define your LaTeX figure

To begin with, assume that you have a figure defined somewhere in a LaTeX document like this:

\caption{A prototype of the Job Information dialog}

(As you’ll see from the many comments below, the order of these lines is very important: The \caption tag must come before the \label tag. Please read the comments for more details.)

Let’s further assume that as it turns out, in the current version of your document, this is Figure 11-1 in the document, and it appears on page 69.

Back to top

2) Reference the figure

Now, somewhere else in my document I want to make a reference to this figure. If I just want to refer to the figure number, I can get it to appear by writing LaTeX text like this:

Please see Figure ~\ref{fig:JobInformationDialog} for a prototype yada yada yada

When I create my output document, such as when I create a PDF with pdflatex, this results in the following output:

Please see Figure 11-1 for a prototype blah blah blah

Now, if I further want to refer to the page number that the image resides on, I can make a reference like this:

Please see Figure ~\ref{fig:JobInformationDialog} on page ~\pageref{fig:JobInformationDialog} for a prototype blah blah blah

If I now compile this statement with pdflatex I’ll end up with a PDF that has this output:

Please see Figure 11-1 on page 69 for a prototype blah blah blah

The \ref and \pageref commands make it very easy to refer to figures that contain labels. As you’ve seen, the text referenced by the \ref and \pageref commands must match the text used within the label command. (It seems to be a convention to begin this text with the string “fig:”. This isn’t really necessary, but because these labels must be unique within a document, it helps to organize your labels, and separate your labels for figures from your labels for tables and equations.

This way of referencing things is very powerful, because you can use the same technique to makes reference to other objects, like tables and equations.

Back to top

Referencing a table

Here’s an example of how I reference a LaTeX table (a longtable in this case):

Table ~\ref{table:prosConsOptionalApproaches} summarizes
the benefits and drawbacks (``Pros and Cons'') of each 

Construct & Benefits & Drawbacks\tabularnewline
Option & Straightforward & Don't get error reason\tabularnewline
Try & Returns error reason & Requires exception\tabularnewline
Or & Returns error reason & Third-party library\tabularnewline
Either & Returns error reason & Works by convention\tabularnewline
\caption{The pros and cons of Scala's optional classes}

This image shows how that LaTeX text is converted into a table in a PDF:

How to reference a LaTeX table

Back to top


In summary, if you wanted to see how to reference a figure or table in LaTeX, I hope these examples are helpful.

Back to top



I've used a command \ref{fig:} to reference my figures, but I don't receive the same numbers in the text as they are in the images.
In my text I have sections and subsections. The image gets the section number (2 digits) while in the text it appears as a 3 digit number.
What should I change?

Thank you!

I don't think I've seen this before, but if you can provide a little more detail, I'll be glad to see if I can help.

I don't know if this will help, especially because it comes from my bad memory, but I used to see reference numbers wrong if I only ran pdflatex one time. As much as I can remember, I think I either ran a command named 'texify' to get the numbers right, or I ran pdflatex more than once ... I'm sorry, I can't remember right now, but I'll try to look at this when I get to my other computer. In the meantime, if you can share any more details, I'll be glad to help.

Hi Alvin,
Thank you very much for your reply, but I still didn't solve my problem.
I'll try to explain it better:
For example, I have 3 figures in Chapter 5. The figures will have reference numbers: 5.1, 5.2, and 5.3. But, if I refer to the first image in a subsection 5.1.3, in the text I will get the reference number 5.1.3 not 5.1. If I refer to the same figure but in a subsection 5.2.2 the text will contain the figure number 5.2.2.

Hope this will look more clear to you.

Thank you.

Sorry, just a quick apology here. Every time I start to look at this I get called away from it. I have written myself a note here, and will block off some time to look into this more tomorrow. I have a good-size document I should be able to test this on.

I'm sorry, I can't duplicate this problem, but I can share some of the code I've used to try to re-create it. First, I define my image and label like this:


FOO, and BAR.

\caption{The description of my image was here.}

Next, I reference this label from somewhere else in my document like this:

(Figure ~\ref{label:MyExampleLabel} on page ~\pageref{label:MyExampleLabel}) YADA YADA YADA

After I generate my PDF, the references look like this:

(Figure 4.2 on page 39) YADA YADA YADA 

and the label on my image looks like this:

Figure 4.2: The description of the image was here.

These are correct, as this is the second image in this section of my document.

Depending on whether or not I use that \clearpage command, the image either shows up in Section 4.8.5 of my document, or it floats to wherever pdflatex thinks it should go.

I'm sorry I can't reproduce the problem ... thinking, thinking ... I haven't upgraded my pdflatex version in several years, so that could be a difference. I just ran pdflatex --version, and I see this output:

pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4)
kpathsea version 3.5.4

I guess I have the PI version of pdfeTeX. Also, I'm running this on Mac OS X 10.5.x.

One other thing I just thought of: Check your pdflatex log file and see if there are any clues in there.

Oops, one last note: here's the pdflatex message I used to see telling me my references were going to be wrong:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

Whenever I saw this message I knew I needed to run pdflatex again.


I have the exact problem. The label for the table seems to cause the reference to refer to the section the table is in instead of the table number itself. I am actually trying to find a way of correcting the problem when i came upon this thread. Hope somebody can help



i came here for the same reason as you claudine, and yes you're right, that does fix it!
thx a lot


I have the same problem with my figures, and moving the label around doesn't seem to change anything. It's quite problematic when four figures give the same reference, which is just the name of the subsection they are placed in.


Hi everyone,

I have the same problem with tables. I only have one table at the moment and its caption calls it 2.1 as it is in chapter 2. However when i refer to in in the text with \ref{table:mism} the result is table 2.2 (which is the chapter and section number - coincidence???)

This happens weather i put the text reference before or after the actual table.

I'm running
pdfTeX 3.1415926-1.40.9-2.2 (Web2C 7.5.7)
kpathsea version 3.5.7

i.e the most recent binary of TexShop for mac



If anyone has a little code they can share with me I'll be glad to run it on my system and see if I can get it to work. All the comments about this problem make me wonder what's up.



\definecolor{purp}{rgb}{0.9, 0.1, 0.9}

%40 left 30 top




\title{test doc}




here is some text, no tables.

Table \ref{table:mism} computes lattice mismatch for various films (horizontal) grown on different substrates and electrodes (vertical). The highlighted fields indicate trials to be undertaken.

\begin{center}\begin{tabular}{lcccccccc} \hline & \textbf{STO} & \textbf{MAO} & \textbf{MgO} & \textbf{Fe$_3$0$_4$} & \textbf{LSMO} & \textbf{SRO} & \textbf{BFO} & \textbf{PZT} \\ \hline \textbf{STO} & -- & -3.465 & -7.841 & -7.501 & \color{green}{0.896} & \color{green}{-0.896} & -1.216 & 0 \\ \textbf{MAO} & 3.349 & -- & -4.230 & \color{green}{-3.901} & 4.215 & 2.482 & 2.173 & 0 \\ \textbf{MgO} & 7.271 & 4.058 & -- & \color{green}{0.316} & 8.102 & 6.440 & 6.143 & 0 \\ \textbf{Fe$_3$0$_4$} & 6.977 & 3.754 & -0.317 & -- & 7.811 & 6.144 & \color{blue}{5.846} & 0 \\ \textbf{LSMO} & -0.904 & -4.400 & -8.816 & -8.473 & -- & -1.809 & \color{blue}{-2.132} & 0 \\ \textbf{SRO} & 0.888 & -2.546 & -6.883 & -6.546 & 1.777 & -- & \color{blue}{-0.317} & 0 \\ \textbf{BFO} & 1.202 & -2.163 & -6.545 & -6.209 & \color{purp}{2.087} & \color{purp}{0.316} & -- & 0 \\ \textbf{PZT} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{tabular} \caption{Lattice mismatch calculations}




First, thanks again for this sample code. And second, I got this to work. The short answer is that I had to move the label to a position immediately after the caption, like this:

\caption{Lattice mismatch calculations}\label{table:mism}

The longer answer is that I dug through an old (but very good) book named The LaTeX Companion, where I found the following information (which I'm pretty much just copying and pasting, forgive me for this plagiarism). The first lines are background information, and the last line (in bold) describes the solution:

For building cross-reference labels, the "currently active" structural element of a document is determined in the following way. The sectioning commands (\chapter, \section, ...), the environments equation, figure, table, and the theorem family, as well as the various levels of the enumerate environment, and \footnote set the current reference string, which contains the number generated by LaTeX for the given element. This reference string is usually set at the beginning of an element and reset when the scope of the element is exited.

Notable exceptions to this rule are the table and figure environments, where the reference string is defined by the \caption commands. This allows several \caption and \label pairs inside one environment. As it is the \caption directive that generates the number, the corresponding \label command must follow the \caption command in question, otherwise an incorrect number will be generated.

(I don't think some of those sentences are grammatically correct, but I double-checked my typing.)

I don't know if this will help all the problems described here, but I hope it does.

Hi Alvin,

Thank you so very much.

I have no idea why it works, but placing the label directly after the caption has solved the problem.




I had the same problem with the figure being referenced by the section instead of just the number I wanted. And hooray, Alvin's solution of putting the label directly after the caption also worked for me.


Thanks, the Post of Claudine helped me get the References straight, I also had the order of caption/label "wrong".


I can't believe changing the order to caption-label worked! I'm so happy! Thank you Claudine!!!


Thnaks for the solution! It was a long standing problem for me.


Thanks to Claudine and to Alvin. Add me to the list of "me too".

Must be one of the fragile commands ... finicky about the order and
contiguousness. As it says, it is because it will actually allow
several caption-label pairs within the same table or figure environment.
That is also a feature of great utility so the fragility has to be


...for the posts! I also switched the occurence of caption and label at some point in my doc and this thread helped me quickly.

Having spent half an hour trying everything I could think of without much luck, I can't say how delighted I was to see you figured a way out of the problem.



Hi Alvin,

Thank you so very much. Your suggestion indeed solved my problem



I struggled with the same figure numbering issue for a couple hours until I found this post. Thanks!


Thank you, I'm glad I found this post! Saved me some hours of debugging!


Thanks for the help!

The form \caption{blah blah}\label{fig:num} works for me, too. I really had no idea how to get it right! Thank you once again! :)


I just ran into the same problem with the figure references. I guess I used to blindly use the correct sequence and couldn't figure out what I was doing wrong today. Thanks for the solution.

Hi Alvin,

thanks a lot for this help. I had been struggling with incorrect numbering of a single table in my thesis and wasn't able to solve it. Today I decided to be patient and solve it. I stumbled upon your post here and to my relief it is working. thanks again,



Thank you this has helped me too.