LaTeX warning · Warnings: references, floats and boxes
LaTeX Warning: Reference `sec:result' on page 1 undefined
Quick answer
LaTeX writes every \label to the .aux file and reads it on the next run, so on the first run every \ref prints ?? and warns. If the warning survives a second compile, the key in \ref does not match any \label exactly: look for a typo, a missing label, or a label in a file that is not included. Labels for figures and tables must come after \caption, otherwise they point to the section instead.
The warning in the log
This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.
LaTeX Warning: Reference `sec:result' on page 1 undefined on input line 4.
LaTeX Warning: There were undefined references.Why it happens
- Only one compile run: references always need two (online editors and latexmk rerun automatically).
- A typo or different spelling:
\ref{sec:result}against\label{sec:results}. Keys are case-sensitive. - The
\labelis missing, commented out, or in a chapter file that is excluded by\includeonly.
How to fix it
Compile twice first. If the warning is still there, copy the key from the message and search for \label{ with that key; correct whichever side is wrong.
For figures and tables, put \label after \caption (or inside it). A label placed before the caption silently refers to the current section, which is a different bug: no warning, but the wrong number.
Broken: reproduces the warning
\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The loss drops quickly (see Section~\ref{sec:result}).
\end{document}Try this in Octree — free LaTeX editor with AI, compiles in your browser
Fixed: compiles cleanly
\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The loss drops quickly (see Section~\ref{sec:results}).
\end{document}LaTeX Warning: Label `fig:loss' multiply defined.
LaTeX Warning: Label `fig:loss' multiply defined.
LaTeX Warning: There were multiply-defined labels.The same key was used by two \label commands, so every \ref to it points to whichever came last. It happens when a figure or equation is copied and pasted with its label, or when two chapter files use the same short labels. Search for the key and rename one of them; a prefix convention such as fig:, tab:, eq: and sec: plus a chapter name avoids the clash.
A label inside an environment that is typeset twice (some tabularx or measurement-based packages) can also trigger it; move the label out of the measured content.
Related errors
- Citation undefined – A
\citekey has no matching bibliography entry yet, so the PDF shows [?]. - Too many unprocessed floats – Figures or tables pile up behind one that LaTeX cannot place, until it runs out of float slots.
- Token not allowed in a PDF string – Math or a command in a section title cannot be copied into the PDF bookmarks.
- All LaTeX errors and warnings – The full list, grouped by cause
Frequently Asked Questions
Why does \ref show ?? in my PDF?
Either LaTeX has only run once (references resolve on the second run) or no \label with exactly that key exists. Compile again; if ?? remains, fix the key so \ref and \label match.
Why does my figure reference show the section number?
The \label comes before \caption. The figure number is set by \caption, so a label above it picks up the current section number. Move the label after the caption.
How do I fix "There were multiply-defined labels"?
Scroll up to the "Label ... multiply defined" warnings, search for each key and rename the duplicates. References to that key will otherwise point to the last label with that name.
Paste your document into Octree — compile errors get a Fix with AI button
When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.
Fix it in Octree →