有什么方法可以让 hyperref 从 toc/lof/lot 中的链接中排除章节/章节等编号?
我想要它是因为我突出显示了链接,而数字实际上并不是部分/章节/等名称的一部分。
我搜索了手册——但找不到选项。也许唯一的方法是重新定义一些 hyperref 外部命令。
编辑:
\documentclass{book}
\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages
% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setmonofont{DejaVu Sans Mono}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[allcolors=blue,colorlinks]{hyperref}
\begin{document}
\tableofcontents
\chapter{foo}
Foo!
\chapter{bar}
Bar!
\chapter{baz}
Baz!
\end{document}
(应该用 XeLaTeX 进行编译)。
答案1
一种有点复杂的方法,仅适用于目录:
\documentclass{book}
\usepackage{hyperref}
\usepackage{etoc}
\makeatletter
% store the original table of contents macros
% (they are not modified by hyperref, only \contentsline is)
\let\latchapter\l@chapter
\let\latsection\l@section
\let\latsubsection\l@subsection
%
% then use the etoc package to feed the l@ macros with a filtered out data
\etocsetstyle{chapter}{}{}
{\latchapter{\numberline{\etocthenumber}\etocname}{\etocpage}}{}
\etocsetstyle{section}{}{}
{\latsection{\numberline{\etocthenumber}\etocname}{\etocpage}}{}
\etocsetstyle{subsection}{}{}
{\latsubsection{\numberline{\etocthenumber}\etocname}{\etocpage}}{}
\makeatother
% ready to go!
\begin{document}
\tableofcontents
\chapter{One}
hello
\section{This is a section}
hello
\subsection{a subsection}
hello
\subsection{another subsection}
hello
\section{Another section}
a
\chapter{Two}
b
\section{And one more section}
c
\subsection{an a subsection}
d
\end{document}