How to make a hyperlink navigate to the top of the figure in LaTeX when using hyperref?

14,239

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.

Share:
14,239
vitaut
Author by

vitaut

GitHub: https://github.com/vitaut Twitter: https://twitter.com/vzverovich Author of {fmt} and C++20 std::format

Updated on June 15, 2022

Comments

  • vitaut
    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
    vitaut over 10 years
    Thanks for the answer. Could you elaborate why it is better?
  • antoine
    antoine over 8 years
    If 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
    Kartoffel over 2 years
    For some reason, the caption package changes the font size of figure captions.