Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I read Margin Figures/captions and the answers within. I have stripped the definition of the marginfloats from the tufte documentclass into the MWE below.

Can the definition of \@tufte@margin@floatbox be tweaked so that the hyperlink goes to the top of the figure, and not below the caption?

\documentclass{article}
\usepackage[left=6cm,right=1cm,showframe=true,
            asymmetric=true]{geometry}               
\usepackage{placeins}
\usepackage{hyperref}

\reversemarginpar
\setlength{\marginparwidth}{5cm}

\makeatletter
% Margin float environment
\newsavebox{\@tufte@margin@floatbox}
\newenvironment{@tufte@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@tufte@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@tufte@margin@floatbox}}%
  }

% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{figure}}
  {\end{@tufte@margin@float}}

% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{table}}
  {\end{@tufte@margin@float}}

\makeatother

\begin{document}

This is a hyperlink to Figure \ref{fig:test}

\newpage

\begin{marginfigure}
 \centering
 \rule{30pt}{20pt}
 \caption{Figure in margin}
 \label{fig:test}
\end{marginfigure}

\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

The hypcap package attempts to find "a solution of the problem with hyperref, that links to floats points below the caption and not at the beginning of the float." (taken directly from the package documentation) Consequently, it provides \capstart to denotes the start of floating environment and where the hyperlink should jump to.

...
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepacakge{hypcap}% http://ctan.org/pkg/hypcap
...
% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{figure}%
   \capstart\endgraf}% <-- Hyperlink jumps to start of 'marginfigure'
  {\end{@tufte@margin@float}}

% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{table}%
   \capstart\endgraf}% <-- Hyperlink jumps to start of 'margintable'
  {\end{@tufte@margin@float}}
share|improve this answer
    
Awesome, thanks for the background and detailed answer. –  cmhughes Sep 3 '11 at 15:40
    
I actually ended up using \usepackage[all]{hypcap} which fixed all of my hyperlinks to floats. –  cmhughes Sep 3 '11 at 18:36
    
@cmhughes: This, or something related, is causing me an error. –  raxacoricofallapatorius May 23 '12 at 2:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.