LaTeX - 使用PDF文档添加可点击的链接到部分/子部分
我使用LaTeX制作PDF。我有几个部分和小节。我想在文档顶部添加一个链接,以便在PDF中有人可以点击它,它会转到该部分/子部分。我知道这可以通过链接目录来实现,但我不想制作目录,我需要更多的控制。LaTeX - 使用PDF文档添加可点击的链接到部分/子部分
包括\usepackage{hyperref}
在您的文档的序言中。使用\ref{}
为您的部分分配正确的标签并引用这些标签。在使用pdflatex创建PDF时,这些引用将会变成可点击的链接。
请注意,要使用hyperref,您不能在'documentclass'中使用'draft'选项! – Cerran 2014-03-07 17:21:31
hyperref
软件包对此类事件有广泛的支持(如前面的答案中所述)。
注意事项和建议:hyperref是一个很大的软件包,并且(必要时)它会在LaTeX的内核中扮演一些非常肮脏的伎俩。最后载入hyperref包,如果文件突然变得很奇怪,那么将该包注释掉,从目录中删除.out
和.aux
文件,然后再次尝试查看问题是否消失。如果确实如此,那么......想一想。
hypertex
包可以做一些相同的事情,并且更轻量一些。但我的回忆是,它有点脆弱,可能不会再维持多久。
您可以使用PDF特色功能(请参阅pdftex手册)来完成这些工作,但这会变得更加困难,并且需要您了解相当多的PDF。
正如在其他答案中指出的那样,您可以使用hyperref package。但是,默认设置是非常糟糕的(它增加了一个盒子,大多数考虑周围的各个环节丑陋的),所以这里是一个典型的代码片段来定制最有用的设置:
\usepackage{hyperref}
\hypersetup{
colorlinks = true, % Colours links instead of ugly boxes
urlcolor = blue, % Colour for external hyperlinks
linkcolor = blue, % Colour of internal links
citecolor = red % Colour of citations
}
此外,如果您使用包natlib(\usepackage{natbib}
),将hyperref宏产生两个链接:
为了解决这个问题,add:
\usepackage{etoolbox}
\makeatletter
\pretocmd{\[email protected]}{%
\let\[email protected]@\[email protected]@citex
\def\[email protected]{#2}%
\setcounter{[email protected]@cites}{0}%
\setcounter{[email protected]@cites}{0}%
\forcsvlist{\stepcounter{[email protected]@cites}\@gobble}{#3}}{}{}
\newcounter{[email protected]@cites}
\newcounter{[email protected]@cites}
\def\[email protected]{}
% include postnote and \citet closing bracket in hyperlink
\def\[email protected]@citex#1{%
\stepcounter{[email protected]@cites}%
\[email protected]{\@citeb\@[email protected]@citeb}#1%
\ifnumequal{\value{[email protected]@cites}}{\value{[email protected]@cites}}
{\[email protected]\else\if*\[email protected]*\else%
\[email protected]\[email protected]\global\def\[email protected]{}\fi\fi}{}%
\[email protected]\else\if\relax\[email protected]\relax
\else\[email protected]@close\global\let\[email protected]\@empty\fi\fi% avoid compact citations
\[email protected]}
\renewcommand\[email protected][2]{#1}
% avoid extraneous postnotes, closing brackets
\patchcmd{\[email protected]}
{\[email protected]\else\if*#2*\else\[email protected]#2\fi
\if\relax\[email protected]\relax\else\[email protected]@close\fi\fi}{}{}{}
\patchcmd{\[email protected]}
{\if\relax\[email protected]\relax\[email protected]@citea\else\[email protected]@[email protected]\fi}
{\if\relax\[email protected]\relax\[email protected]@citea\else\[email protected]@[email protected]\fi}{}{}
\makeatother
文档顶部的链接非常正好是目录的内容。你的链接与ToC有什么不同? – Philipp 2010-07-14 09:23:05
Philipp,我想要一个更多的自定义布局,而不是像默认的ToC这样的列表。我现在已经完成了布局,我认为添加链接可能会比制作ToC看起来更容易。 – Rory 2010-07-14 10:13:53