Graphics, Figures & TablesReferencing the top of the nonfloat figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
moun
Posts: 2
Joined: Sun Feb 07, 2010 6:22 pm

Referencing the top of the nonfloat figure

Post by moun »

Hi,

I have figures in my document that are referenced from the text. Figures have caption and labels below them. When I click on the reference hyperlink (in PDF), I expect to jump to the top of the picture, but I jump to the caption, what is rather inconvenient.
For standard figures (as floats) I have solved it using hypcap package and its \capstart command, what works like a charm.

Code: Select all

\begin{figure}[ht]
  \capstart
  \begin{center}%
    \includegraphics[#1, clip, keepaspectratio]{#2}
  \end{center}\caption{#3}\label{fig:#2}
\end{figure}
However I have also nonfloat-figures (nonfloat package) in my text that are inserted in a shaded environment (framed package) and there is no \capstart equivalent for nonfloats and the regular \capstart does not work.

Code: Select all

\begin{samepage}%
  \begin{center}%
    \includegraphics[#1, clip, keepaspectratio]{#2}%
  \end{center}
  \figcaption{#3}%
  \label{fig:#2}
\end{samepage}
Has anybody an idea, how to solve or circumvent the problem?

Thanx

Tom

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Referencing the top of the nonfloat figure

Post by gmedina »

Hi,

use the caption package (make sure that your system has a recent version: 3.1x). It automatically handles the problem for the standard figure and table environments (if hyperref has been loaded). For non-floating objects, use a minipage environment, together with the \captionsetup command, as described in the package documentation (Section 6.5 hyperref and Section 6.6 hypcap).

A little example:

Code: Select all

\documentclass{article}
\usepackage{caption}
\usepackage{hyperref}

\begin{document}

\begin{figure}[!ht]
  \centering
  \rule{4cm}{6cm}
  \caption{A standard figure}
  \label{fig:test1}
\end{figure}

\noindent\begin{minipage}{\textwidth}%
  \captionsetup{type=figure}
  \centering
  \rule{4cm}{13cm}
  \caption{A non-floating figure}
  \label{fig:test2}
\end{minipage}

\newpage

\ref{fig:test1} \ref{fig:test2}

\end{document}
As you can see there's no need to load the hypcap package and now the nonfloat package is no longer needed.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
moun
Posts: 2
Joined: Sun Feb 07, 2010 6:22 pm

Referencing the top of the nonfloat figure

Post by moun »

Thank you very much, gmedina, \captionsetup was the magic word I needed.
Post Reply