39

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
vitaut
  • 49,672
  • 25
  • 199
  • 336

3 Answers3

35

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.

nbz
  • 3,806
  • 3
  • 28
  • 56
32

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.

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
michalko
  • 436
  • 4
  • 3
  • 1
    If for some reason you can't use the caption package, you can prevent hypcap compilation errors for figures without a caption with `\capstartfalse` http://tex.stackexchange.com/a/240261/88028 – antoine Oct 06 '15 at 01:32
  • For some reason, the caption package changes the font size of figure captions. – Kartoffel Sep 29 '21 at 11:59
0
\usepackage{hyperref}
\usepackage{caption}

Using this is a better idea than \usepackage[all]{hypcap}.

kleopatra
  • 51,061
  • 28
  • 99
  • 211