LaTeX教程(016)- LaTeX \LaTeX LATEX文档结构(16)
接上一讲
我们前面知道,\vref
是对\ref
的升级,而varioref
包也提供了一个对\pageref
升级的命令\vpageref
。它和\vref
的原理很相似,内置了一些判断。
\vpageref[same-page][other-page]{key}
在不指定选项的前提下,它所输出的内容就是\vref
字符串去掉其中的\ref
字符串。例如,如果\ref
的输出是3.3
,而\vref
输出(我们假设引用和引用对象在彼此的对面)就是3.3 on the facing page
,那么\vpageref
的输出就是on the facing page
,没有前面\ref
生成的索引字符串。其它情形依此类推,分别是on the preceding page,on the following page以及on page x。只有引用和引用对象在同一页的时候和\vref
不同,这种情况下,\vpageref
会输出on the current page。该情形下的字符串被存储在命令\reftextcurrent
中,重定义这个命令可以将"on the current page"改成其他你想要的字符串。
另外,\vpageref
生成的字符串中,只有on page x中的x
可以被自动转换为超链接。
注意,不管使用\vref
还是\vpageref
,最好在命令前后分别放置一个空格,否则它们生成的字符串很可能会和前后文本连在一起。当然,如果是在一个段落的开头,那么前面的空格就不需要了。
\vpageref
比\vref
多了一个选项。其中same-page
选项和\vref
的same-page
选项作用相同,用来代替引用和引用对象在同一页时的输出字符串。而other-page
用于其他情况,也就是引用和引用对象不在同一页的情况。这种情况下,other-page
中内容会放置在原本的输出内容的前面。如"other-page
+on the preceding page"等。我们可以做个测试:
\documentclass{book}
\usepackage[a5paper,margin=1.5in]{geometry}
\usepackage[nospace]{varioref}
\usepackage{kantlipsum}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\begin{document}
\chapter{A chapter}
\vpageref[same][other]{test}
\kant[1]
\vpageref[same][other]{test}
\kant[2]
\label{test}
\kant[3]
\vpageref[same][other]{test}
\chapter{A chapter two}
\vpageref[same][other]{test}
\end{document}
这里不截图了,自行编译一下。因为有交叉引用,记得要编译两遍。
实际上,像"on the preceding page","on the following page"等文本,也有存储它们的命令,它们分别是
\reftextafter
\reftextafter
\reftextfacebefore
\reftextfaceafter
我们将在下文中讲解这些命令。
\vpageref
的星号变体\vpageref*
和其原型不同的是它不会生成超链接(注意,经笔者本人测试,该机制并不总是有效的)。
\vpagerefrange
命令,其形式如下:
\vpagerefrange[same-page]{first}{last}
\vpagerefrange*[same-page]{first}{last}
它和\vpageref
很像,不同的地方是它有两个必选参数,而只有一个选项。该命令用两个索引来确定一个范围,它可以生成如"on page 15-18"这样的索引字符串。我们用一个例子演示一下:
\documentclass{book}
\usepackage[a5paper,margin=1.5in]{geometry}
\