6

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}
3

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}}
  • 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. – orome May 23 '12 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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