我正在使用 Fancyref (\Fref{}) 包进行交叉引用,但每个引用都采用“下一页图 4“。我怎样才能告诉包只包含”第 xxx 页“如果参考目标很远(例如超过5页)?
答案1
包fancyref
使用包varioref
. \reftextafter
,\reftextbefore
可以重新定义为隐藏其文本。\reftextfaraway
如果引用的对象距离五页或更多页,也可以重新定义为仅打印文本:
\documentclass{article}
\usepackage{fancyref}
\renewcommand*{\reftextfaceafter}{\unskip}
\renewcommand*{\reftextafter}{\unskip}
\renewcommand*{\reftextfacebefore}{\unskip}
\renewcommand*{\reftextbefore}{\unskip}
\makeatletter
\let\saved@reftextfaraway\reftextfaraway
\renewcommand*{\reftextfaraway}[1]{%
\begingroup
\def\ref@unknown@value{??}%
\ifx\@tempa\ref@unknown@value
\count@=0 %
\else
\count@\thevpagerefnum\relax
\advance\count@ by -\@tempa\relax
\ifnum\count@<0 \count@=-\count@\fi
\fi
\ifnum\count@<5 %
\unskip
\else
\saved@reftextfaraway{#1}%
\fi
\endgroup
}
\makeatother
\begin{document}
\begin{figure}
\caption{Dummy figure}
\label{fig:dummy}
\end{figure}
\clearpage
\Fref{fig:dummy} contains a dummy figure.
\clearpage
\Fref{fig:dummy} contains a dummy figure.
\clearpage
\Fref{fig:dummy} contains a dummy figure.
\clearpage
\Fref{fig:dummy} contains a dummy figure.
\clearpage
\Fref{fig:dummy} contains a dummy figure.
\end{document}
结果:
<Page 1> Figure 1: Dummy figure <Page 2> Figure 1 contains a dummy figure. <Page 3> Figure 1 contains a dummy figure. <Page 4> Figure 1 contains a dummy figure. <Page 5> Figure 1 contains a dummy figure. <Page 6> Figure 1 on page 1 contains a dummy figure.