How to make a hyperlink navigate to the top of the figure in LaTeX when using hyperref?
Solution 1
Add this in your preamble
\usepackage{hyperref}
\usepackage[all]{hypcap} %for going to the top of an image when a figure reference is clicked
Make sure that the \usepackage[all]{hypcap} is written after the hyperref package is imported.
Solution 2
To previous comment:
\usepackage{hyperref}
\usepackage{caption}
is slightly better than \usepackage[all]{hypcap}
because when you use e.g. figure
without captions there won't be a compilation problem. The caption package by default sets option
hypcap=true
anchoring hyperlinks to the beginning of an environment.
vitaut
GitHub: https://github.com/vitaut Twitter: https://twitter.com/vzverovich Author of {fmt} and C++20 std::format
Updated on June 15, 2022Comments
-
vitaut about 2 years
I have a LaTeX document with a figure and references to it:
\begin{figure} ... \caption{...} \label{fig:1} \end{figure} \ref{fig:1}
I use the hyperref package to get hyperlinks in the resulting PDF. However the link to the figure navigates to the caption leaving the figure itself out of the view. How can I make it navigate to the start of the figure instead without moving the caption to the top?
-
vitaut over 10 yearsThanks for the answer. Could you elaborate why it is better?
-
antoine over 8 yearsIf for some reason you can't use the caption package, you can prevent hypcap compilation errors for figures without a caption with
\capstartfalse
tex.stackexchange.com/a/240261/88028 -
Kartoffel over 2 yearsFor some reason, the caption package changes the font size of figure captions.