![边距浮动和超链接](https://linux22.com/image/240205/%E8%BE%B9%E8%B7%9D%E6%B5%AE%E5%8A%A8%E5%92%8C%E8%B6%85%E9%93%BE%E6%8E%A5.png)
我读边注/标题marginfloats
以及其中的答案。我已将 documentclass中的定义剥离tufte
到下面的 MWE 中。
是否可以调整定义\@tufte@margin@floatbox
以便超链接转到图的顶部,而不是标题下方?
\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}
答案1
这hypcap
包裹尝试找到“hyperref 问题的解决方案,该解决方案链接到标题下方的浮点,而不是浮点的开头。”(直接取自包装文档) 因此,它提供了\capstart
表示浮动环境的开始以及超链接应该跳转到的位置。
...
\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}}