# Table cross-chapter reference works fine but shows “??”

When I reference a table in a posterior chapter in my thesis, instead of the correct table number it puts ??. However, the link works correctly, and the table appears in the List of Tables fine.

I reference it as:

\ref{tab:datasets}

The table is:

\begin{table}[h] \label{tab:datasets} ...

The log shows

Reference 'tab:datasets' on page 16 undefined

How can I make Latex show the proper table number?

• Put the label behind the caption. – Ulrike Fischer Jun 24 '15 at 14:26
• And you need to compile at least twice. The label number is written to the .aux file and read at the beginning (\begin{document}) of the next LaTeX run. – Heiko Oberdiek Jun 24 '15 at 14:31
• @HeikoOberdiek: As the table appears in the list of table and links work I think one can assume that the document has been compiled twice. – Ulrike Fischer Jun 24 '15 at 14:54
• @UlrikeFischer That does not explain the question marks. The \label could be added at a later time, the the auxiliary files already contain the caption, but not yet the label. – Heiko Oberdiek Jun 24 '15 at 15:01
• @UlrikeFischer gave the correct answer. – CrystalCalculator Jun 24 '15 at 15:33

You need to run the program twice, one after another. And before that, be sure you have used the standard \label-\ref system: \label{labelname} and \ref{labelname}. In your case \label{tab:datasets} and \ref{tab:datasets}. Try to avoid using the same "label name" more times.