LaTeX Warning: Reference `<label>' on page <n> undefined

A \ref, \eqref or \pageref names a label LaTeX has not seen: a typo, a missing \label, or a part excluded by \includeonly. Prints ?? in the PDF.

Help centre › LaTeX errors › References and bibliography · Warning: the document still compiles

What the log says

LaTeX Warning: Reference `fig:results' on page 2 undefined on input line 31.
...
LaTeX Warning: There were undefined references.

What it means

The label in \ref{…} was not defined anywhere in the previous run's .aux file. The PDF shows ?? where the number should be. On a first compile this is normal: labels are written to the .aux file in one pass and read in the next. If it survives a second pass, the label really does not exist.

Causes and fixes

Most common first. Each example is a complete document; the first fails with this message, the second is the same document fixed.

1. The label in \ref is spelled differently from the \label

Labels are case-sensitive and match character by character, so fig:Results, fig:result and fig:results are three labels. Search the source for \label{ and copy the exact text.

Fails
\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The results are discussed in Section~\ref{sec:result}.
\end{document}
Fixed
\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The results are discussed in Section~\ref{sec:results}.
\end{document}

2. The label is in a chapter excluded by \includeonly

With \includeonly{…}, chapters left out are not typeset, and their labels are known only if their .aux files survive from an earlier full compile. Remove \includeonly (or add the chapter to it) and compile the whole document once.

Fails
\begin{filecontents*}[overwrite]{intro.tex}
\chapter{Introduction}\label{ch:intro}
Some background.
\end{filecontents*}
\begin{filecontents*}[overwrite]{methods.tex}
\chapter{Methods}
As set out in Chapter~\ref{ch:intro}, we measure twice.
\end{filecontents*}
\documentclass{report}
\includeonly{methods}
\begin{document}
\include{intro}
\include{methods}
\end{document}
Fixed
\begin{filecontents*}[overwrite]{intro.tex}
\chapter{Introduction}\label{ch:intro}
Some background.
\end{filecontents*}
\begin{filecontents*}[overwrite]{methods.tex}
\chapter{Methods}
As set out in Chapter~\ref{ch:intro}, we measure twice.
\end{filecontents*}
\documentclass{report}
\begin{document}
\include{intro}
\include{methods}
\end{document}

3. The \label was never written, or is commented out

A figure or table needs \label{…} inside its environment, after \caption{…}; an equation needs it inside equation or align. Check that the line carrying the label is not behind a %.

4. Only one pass has run

Labels reach the .aux file in one LaTeX run and are read in the next. Compile again; latexmk repeats the passes automatically.

Finding the line when the line number does not help

In Manulyx

The editor shows the warning beside the line with the \ref. Manulyx repeats the LaTeX passes itself, so a reference that only needed a second pass resolves without you doing anything.

Write in Manulyx for free · Journal templates

More in references and bibliography

Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors