Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

hyperref and figures

305 views
Skip to first unread message

Gekke Eekhoorn

unread,
May 29, 2000, 3:00:00 AM5/29/00
to
Hi everyone,

I have the following problem: I have a nice setup to generate pdf files,
but somehow hyperref makes hyperlinks to figures point just under the caption
of the figure. Needless to say, you can't read the captions. On top of that,
I prefer my caption under the figures, so you don't see the figure at all...

I make my figures as follows:
\begin{figure}
\includegraphics{...}
\caption{...}
\label{...}
\end{figure}

Is there some way to make the reference to the label point to the beginning
of the bounding box of the figure? I tried reading the source, but TeX is not
really intuitive to me :). Furthermore, I found nothing on dejanews.

Help me Obi-wan!

Thanks in advance,

Wout.

Sebastian Rahtz

unread,
May 29, 2000, 3:00:00 AM5/29/00
to
Gekke Eekhoorn <ge...@beneden.pandora.be> writes:


> Is there some way to make the reference to the label point to the beginning
> of the bounding box of the figure?

In a word, "no". Its a complicated business, because a `figure' can
contain several captions and pictures. In the general case, working
out what the caption actually refers to (in the way of bounding box)
is pretty damned hard.

Sebastian

Heiko Oberdiek

unread,
May 29, 2000, 3:00:00 AM5/29/00
to
Sebastian Rahtz <sebasti...@computing-services.oxford.ac.uk>
wrote:

I agree with Sebastian, in general it is not possible.
In limited and special cases you can try package `hypcap',
that I have written last year. But have to mark the
begin of the figure with \capstart or you can use
option `figure', but then each figure environment
has to use a \caption command, ...
It does not work with package `subfigure' and I expect
problems with similar packages.

Yours sincerely
Heiko <ober...@ruf.uni-freiburg.de>

%%% cut %%% hypcap.sty %%% cut %%%
% hypcap.sty
%
% Author: Heiko Oberdiek
% Copyright (c) 1999 by Heiko Oberdiek.
%
% Function: Setting the anchor for the link of \caption separatly
% This package tries a solution of the problem with
% hyperref that links to figures points below the
% caption.
%
% Use:
% * In short, if you want to fix all figure environments that
% have all one \caption, try:
% \usepackage[figure]{hypcap}% after \usepackage{hyperref}
%
% * Important: Load package _AFTER_ hyperref
%
% * \caption is divided into two parts:
% a) If a \capstart is present, then it increments the counter
% and sets the link anchor.
% b) Then \caption performs then the rest and omits the tasks,
% that are done by \capstart.
% Example:
% \usepackge{hypcap} % _AFTER_ hyperref!
% \begin{figure}
% \capstart
% ...
% \caption{...}
% \end{figure}
% ==> The link from \ref or \listoffigures points now to the
% top of the figure not below.
%
% several \captions in a figure environment:
% \capstart...\caption...\capstart...\caption
%
% * In order not to specify \capstart at the begin of a
% float environment, you can use the options:
% figure, figure*, table, table*
% The the correspondending environment is overloaded to
% execute \capstart automatically. Then there must be a
% \caption in every environment of this type.
% For another \captions in the environment you need
% \capstart again.
%
% * Because it looks poor, if the link points exactly at top of
% the figure, there is additional space: \hypcapspace
% the default is "0.5\baselineskip".
% \renewcommand{\hypcapspace}{0pt} removes it
% \renewcommand{\hypcapspace}{1pt} sets a fix value.
%
% Please send bugreports, suggested improvements to the author:
% Heiko Oberdiek <ober...@ruf.uni-freiburg.de>
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hypcap}[1999/02/13 v1.0 Adjusting caption anchor
(HO)]

\@ifundefined{hyper@@anchor}{%
\PackageError{hypcap}{You have to load 'hyperref' first}%
\endinput
}{}

\newcommand*\hc@org@caption{}
\let\hc@org@caption\caption

\newcommand*\hc@caption{%
\@dblarg{\@caption\@captype}% second part of caption
}

\newif\if@capstart

\newcommand*\hypcapspace{.5\baselineskip}

\newcommand*\capstart{%
\H@refstepcounter\@captype % first part of caption
\hyper@makecurrent\@captype
\vspace*{-\hypcapspace}%
\hyper@@anchor\@currentHref\relax
\vspace*{\hypcapspace}%
\let\caption\hc@caption
\@capstarttrue
}

\def\hc@caption{%
\@dblarg{\hc@@caption\@captype}%
}

\long\def\hc@@caption#1[#2]#3{%
\let\caption\hc@org@caption
\@capstartfalse
\hyper@makecurrent\@captype
\par\addcontentsline{%
\csname ext@#1\endcsname}{#1}{%
\protect\numberline{%
\csname the#1\endcsname
}{\ignorespaces #2}%
}%
\begingroup
\@parboxrestore
\normalsize
\@makecaption{\csname fnum@#1\endcsname}{%
\ignorespaces#3%
}%
\par
\endgroup
}


\def\hc@redef#1{%
\expandafter\hc@@redef\csname hc@org#1\expandafter\endcsname
\csname hc@orgend#1\expandafter\endcsname
\expandafter{#1}%
}
\def\hc@@redef#1#2#3{%
\expandafter\let\expandafter#1\csname#3\endcsname
\expandafter\let\expandafter#2\csname end#3\endcsname
\renewenvironment*{#3}[1][]{%
\ifx\\##1\\%
#1\relax
\else
#1[##1]%
\fi
\capstart
}{%
\if@capstart
\PackageError{hypcap}{You have forgotten to use
\string\caption}%
\else
\fi
#2%
}
}

\DeclareOption{figure}{\hc@redef{\CurrentOption}}
\DeclareOption{figure*}{\hc@redef{\CurrentOption}}
\DeclareOption{table}{\hc@redef{\CurrentOption}}
\DeclareOption{table*}{\hc@redef{\CurrentOption}}
\ProcessOptions\relax
\let\hc@redef\@undefined
\let\hc@@redef\@undefined
\endinput
%%% cut %%% hypcap.sty %%% cut %%%

0 new messages