How to Fix a pdfTeX Link-Nesting Error with \resizebox
At a glance
- 1. Read the error
pdfTeX reports that a hyperlink starts and ends at incompatible nesting levels; the resize command may only expose the problem.
- 2. Find the link
Check the resized content for references, URLs, citations, or other commands that create hyperlinks.
- 3. Test the cause
Temporarily remove hyperlinks or the resizebox, then compile to see which change removes the error.
- 4. Apply a workaround
Disable links in the resized material or move clickable content outside the box.
The message \pdfendlink ended up in different nesting level than \pdfstartlink is a PDF hyperlink error. It means pdfTeX encountered the end of a link at a different level of the typeset box structure from where that link began. The error may appear at \end{document}, even though the problematic content is earlier.
\resizebox packages its contents into a box and scales that box. A hyperlink inside a resized table can expose a mismatch, but the command is not automatically the cause: another link elsewhere in the document may be responsible. The key is to find the command that creates the link and test it separately.
Check for links in the resized content
With hyperref loaded, commands such as \ref, \cite, \url, and \href can create PDF links. Check every cell and any captions or surrounding material for these commands. A link can also be nested accidentally, for example by placing \href around text that already contains a linked \ref.
First compile a copy of the document with the \resizebox removed. If the error disappears, inspect the resized material for links. Then try removing or disabling one link at a time. If the error remains without the resize command, look for links elsewhere, especially nested links or links crossing unusual box or grouping boundaries.
Disable a link inside the resized table
If the link is not essential, use hyperref’s starred reference command to print a reference without making it clickable. This example includes the required graphicx package for \resizebox and hyperref for the link behavior:
\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\begin{table}[ht]
\centering
\resizebox{\linewidth}{!}{%
\begin{tabular}{ll}
Item & Section\\
Example & \ref*{sec:method}
\end{tabular}%
}
\caption{A resized table with a non-clickable reference.}
\end{table}
\section{Method}\label{sec:method}
The reference in the table prints the section number without a link.
\end{document}
In this example, \ref*{sec:method} prints the same reference number as \ref{sec:method}, but does not create a hyperlink. The table can still be resized, and the reference remains readable; it just is not clickable. The % after the opening brace helps prevent unwanted whitespace from entering the resized box.
For a group of linked commands, you can also suppress hyperlinking in a local region using the NoHyper environment provided by hyperref:
\begin{NoHyper}
... material that should not contain clickable links ...
\end{NoHyper}
Use this only around material where losing clickable links is acceptable. It does not repair a badly nested \href; it prevents links from being made in that region.
Keep clickable material outside the box
When readers need the link, restructure the table so that the clickable text is not part of the resized content. For example, use a short plain-text label in the resized table and place the URL or linked reference in a footnote or a nearby sentence. If the table is simply too wide, try reducing its font size or using a wrapping column type such as p{...} or tabularx instead of scaling the entire table. These approaches may preserve more readable text, though any hyperlinks still need to be well formed.
Avoid wrapping a link in another link. For example, \href{...}{See \ref{sec:method}} can nest a link if \ref is made clickable by hyperref. Use \ref* inside the outer link, or place the two links separately.
Common mistakes
- Assuming the final line identifies the source. TeX may report the error only when it finishes writing the PDF. Inspect the table and document content before the reported line.
- Removing
\resizeboxwithout checking links. This is a useful test, not a guaranteed fix; the offending link may be elsewhere. - Using a starred reference but leaving another link in the cell. A
\url,\cite, or\hrefelsewhere in the resized content can still cause trouble. - Keeping nested links. A link should not contain another clickable link. Disable the inner link or reorganize the text.
- Treating every overwide table with scaling. A smaller font or wrapped columns can avoid scaling the table and often improve legibility.
If the smallest example that still fails contains a particular link command inside \resizebox, test that exact command on its own. The precise fix depends on which command creates the link and how the table is structured.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.