如何链接到每一页的目录?

如何链接到每一页的目录?

我怎样才能在每一页上添加指向目录的链接(我猜页码是添加链接的最佳位置)?我尝试搜索,但没有找到任何东西,而且我的 LaTeX 水平不够好,无法自己做这件事。

谢谢!

答案1

您可能知道,使用hyperref包很容易将链接的\ref条目添加到章节或页面(使用\pageref)。棘手的部分是标记目录,因为您不能将其放在章节命令之后,例如\section{foo}\label{foo}。解决方案是:

\tableofcontents\label{retoc} % well, really not very tricky ...

然后,如果您想要其他链接章节号或目录页码的内容,请在其他地方使用 \hyperref[label]{text}。因此,您可以在页眉或页脚中添加一些类似以下内容的内容:

\hyperref[retoc]{Page \thepage}

除了\label,您还可以使用\hypertarget。这里的问题是,这里有第二个参数(要显示的文本),并且只能位于目录之前、目录之后或目录本身。但将整个目录标记为目标(可能包含多个页面)是比较棘手的(现在真的)。为了避免 的消化不良,似乎可以保护它,至少在这个例子中,然后在页眉或页脚中\hypertarget创建 链接。MWE:\hyperlink

\documentclass{book}
\title{Foo}
\author{Foo}
\date{}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancypagestyle{plain}{ \fancyhf{}  \fancyfoot[C]{ --- \hyperlink{toc}{\thepage} --- }}
\pagestyle{fancy}
\fancyhf{}\rhead{ \hyperlink{toc}{Page \thepage}}
\usepackage{emptypage}
\begin{document}
\frontmatter
\maketitle
\renewcommand\contentsname{\protect\hypertarget{toc}{Foo}}
\tableofcontents
\mainmatter
\chapter{Foo} \lipsum[1-3]
\section{Foo} \lipsum[1-3]
\subsection{Foo} \lipsum[1-3]
\chapter{Foo} \lipsum[1-3]
\section{Foo} \lipsum[1-3]
\subsection{Foo} \lipsum[1-3]
\end{document}

相关内容