Scissor LaTeX 中的 hyperref 和 url
hyperref 和 url 宏包在 Scissor LaTeX 中基本可用:\href、\url、\hyperref[label]{text}、\autoref 和 \nameref 都可用,而链接颜色、PDF 元数据等 \hypersetup 选项会被忽略,\nolinkurl 无法识别。
宏包的作用
hyperref 把 PDF 中的引用、文献引用和网址变成可点击的链接,并增加了用于链接的命令:\href{url}{text}、\url{...}、\hyperref[label]{text},以及会输出对象类型和编号(“Section 2”)的 \autoref{label}。\hypersetup{...} 用来设置链接颜色和 PDF 属性。单独的 url 宏包提供 \url。
这里可用的功能
| 命令 | 在 Scissor LaTeX 中 | 说明 |
|---|---|---|
\href{url}{text} | 可用 | 也支持 mailto: 地址。 |
\url{...} | 可用 | _ 等字符无需转义。地址使用正文字体,而不是等宽字体。 |
\hyperref[label]{text} | 可用 | 输出文本。 |
\autoref{label} | 可用 | “Section 1”、“Figure 2”等。 |
\nameref{label} | 部分可用 | 输出编号,而不是章节标题。 |
\pageref{label} | 可用 | |
\hypersetup{...}、宏包选项 | 忽略 | 链接颜色、边框和 PDF 元数据不会生效。 |
\nolinkurl{...} | 不支持 | 会被跳过并在“问题”标签页中注明;文本保留。 |
示例
指向网页、电子邮件地址和章节的链接,以及 \autoref:
\href、\url、\hyperref 和 \autoref
\section{Results}\label{sec:results}
The data is on \href{https://example.com/data}{the project page},
and the raw files are at \url{https://example.com/raw_data/v44}.
Write to \href{mailto:erika@example.com}{Erika Mustermann}.
See \hyperref[sec:results]{the results} or \autoref{sec:results}.用于图和表的 \autoref,以及在这里输出编号的 \nameref:
\autoref 和 \nameref
\section{Method}\label{sec:method}
\begin{table}[h]
\centering
\begin{tabular}{lr} Erika & 44 \\ John & 38 \\ \end{tabular}
\caption{Scores.}\label{tab:scores}
\end{table}
\autoref{tab:scores} lists the scores; \nameref{sec:method}
describes how they were measured.\hypersetup 会被接受,但颜色不会生效:
\hypersetup 被忽略
\documentclass{article}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue, linkcolor=red}
\begin{document}
A link to \href{https://example.com}{example.com} in plain black.
\end{document}兼容性
- 从 TeX 发行版迁移到这里: 链接和引用都可用。
\hypersetup中的链接颜色和 PDF 属性不会生效,\nameref给出的是编号而不是标题。 - 从这里迁移到 TeX 发行版: 文档无需修改即可在那里编译。像往常一样,把
hyperref放在所有宏包的最后加载。
完整手册见 CTAN:ctan.org/pkg/hyperref 和 ctan.org/pkg/url。使用指南请参阅链接和网址和标签和交叉引用。关于 \cref,请参阅 cleveref。
常见问题
导出的 PDF 中的链接可以点击吗?
\href 和 \url 的链接指向各自的地址,\ref、\autoref 和 \hyperref 会在 PDF 中跳转到各自的目标。
为什么我的链接没有颜色?
\hypersetup 和 hyperref 的颜色选项会被忽略,所以链接看起来和周围的文字一样。这样 PDF 也更适合直接打印。
本页的每个示例都在构建网站时由 Scissor LaTeX 排版。 最后更新:2026-11-07