LaTeX - 将可点击的链接添加到 PDF 文档的部分/子部分
我正在用 LaTeX 制作 PDF。我有几个部分和小节。我想在文档顶部放置一个链接,以便在 PDF 中有人可以单击它,然后它会转到该部分/小节。我知道可以使用可链接的目录来实现此目的,但我不想制作目录,我需要更多的控制。
I am making PDF with LaTeX. I have a few sections and subsections. I want to put a link towards the top of the document so that in the PDF someone can click on it and it'll go to that section/subsection. I know it's possible to have this with a linkable table of contents, but I don't want to make a table of contents, I need more control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在文档的序言中包含
\usepackage{hyperref}
。为您的部分分配适当的标签,并使用\ref{}
引用这些标签。当使用 pdflatex 创建 PDF 时,这些参考文献将被转换为可点击的链接。Include
\usepackage{hyperref}
in the preamble of your document. Assign proper labels to your sections and reference these labels using\ref{}
. These references will then be turned into clickable links when creating PDFs with pdflatex.正如其他答案中所指出的,您可以使用 hyperref 包。但是,默认设置非常糟糕(它在每个链接周围添加了一个大多数人认为丑陋的框),因此这里是一个典型的代码片段,用于自定义最有用的设置:
此外,如果您使用包 natlib (
\ usepackage{natbib}
),hyperref 将生成两个链接:要解决此问题,添加:
As pointed to in the other answers, you can use the hyperref package. However, the default settings are pretty bad (it adds a box that most consider ugly around each link), so here is a typical code snippet to customize the most useful settings:
Also, in case you use the package natlib (
\usepackage{natbib}
), hyperref will produce two links:To fix this, add:
hyperref
包对此类事情提供了广泛的支持(如之前的答案中所述)。注意和建议:hyperref 是一个大包,并且(必然)它利用 LaTeX 的本质玩了一些非常肮脏的把戏。最后加载 hyperref 包,如果你的文档突然变得奇怪,那么注释掉该包,从你的目录中删除
.out
和.aux
文件,然后尝试再次查看问题是否消失。如果确实如此,那么……想想办法。hypertex
包可以做一些相同的事情,并且更加轻量级。但我的记忆是它有点脆弱,可能已经不再维护了。您可以使用 PDF 特辑来做一些这样的事情(请参阅 pdftex 手册),但这有点硬核,并且需要您对 PDF 有相当多的了解。
The
hyperref
package has extensive support for this sort of thing (as noted in an earlier answer).Notes and advice: hyperref is a big package, and (by necessity) it plays some pretty dirty tricks with the guts of LaTeX. Load the hyperref package last, and if your document suddenly becomes weird, then comment that package out, get rid of the
.out
and.aux
files from your directory, and try again to see if the problem disappears. If it does, then ... think of something.The
hypertex
package can do some of the same things, and is a little more lightweight. But my recollection is that it's a little fragile, and may not be much maintained any more.You can do some of this stuff with PDF specials (see the pdftex manual), but that's getting a little hardcore, and requires you to know quite a bit about PDF.
除了 Franck 关于超链接样式的评论之外,还可以通过添加 hidelinks 选项来删除所有标记。
In addition to Franck's comment about hyperlink styles, it is possible to remove all markup by adding the hidelinks option.