LaTeX warning "Reference `sec:methods' on page 1 undefined": cause and fix
A \ref or \pageref uses a label that LaTeX does not know in this run. The PDF shows ?? in its place. At the end of the log, "There were undefined references" tells you that at least one such warning occurred.
Why it happens
- The name in
\ref{...}differs from the name in\label{...}. Label names are case-sensitive. - The document was compiled once only. LaTeX writes the labels into the
.auxfile in one run and reads them in the next, so on the first run every reference is undefined. - The
\labelwas deleted or renamed together with its section, figure or equation.
How to fix it
- Compile a second time. If the warning stays, the label does not exist.
- Search the project for the name in the message and compare it with the
\labelyou meant. - Give labels a prefix for their kind, such as
sec:,fig:,tab:andeq:. Typos then stand out. See Cross-references in LaTeX.
A document that produces the message
\documentclass{article}
\begin{document}
\section{Method}\label{sec:method}
Section~\ref{sec:methods} describes the method.
\end{document}Tools run in this order: pdflatex → pdflatex.
The corrected document
\documentclass{article}
\begin{document}
\section{Method}\label{sec:method}
Section~\ref{sec:method} describes the method.
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.