LaTeX 中的链接和网址
加载 hyperref,然后用 \url{https://...} 显示网址,或用 \href{https://...}{link text} 为文字加上链接;两者在 PDF 中都会成为可点击的链接。
\url 和 \href
\url{...} 输出网址,其中可以包含无需转义的 _、%、# 和 ~,并为它加上链接。\href{address}{text} 可以为你选择的任何文字加上链接。
一个网址和一个带链接的短语
The data is at \url{https://example.com/data_2024/v44}.
Read the \href{https://example.com/guide}{short guide} first.在 Scissor LaTeX 生成的 PDF 中,两者都是可以点击的链接。在页面上它们看起来和周围的文字一样:链接不着色,也没有边框。
电子邮件和其他类型的链接
\href 接受任何类型的地址,所以 mailto: 会生成一个电子邮件链接。
电子邮件链接
Questions go to
\href{mailto:erika.mustermann@example.com}{Erika Mustermann}.文档内部的链接
\hyperref[label]{text} 把你自己的文字链接到一个标签,例如某个章节。要把章节编号输出为链接,用 \ref 就够了;\autoref 会加上“Section”一词(参见标签与交叉引用)。
用 \hyperref 链接到标签
\section{Appendix notes}
\label{sec:notes}
Details are in the \hyperref[sec:notes]{notes at the end},
which is \autoref{sec:notes}.命令和设置
| 命令 | 在 Scissor LaTeX 中 | 说明 |
|---|---|---|
\url{address} | 可用 | 按输入原样显示,并加上链接。 |
\href{address}{text} | 可用 | 支持 http、https、mailto 及其他协议。 |
\hyperref[label]{text} | 可用 | 链接到该标签。 |
\path{...} | 可用 | 以等宽字体显示,不加链接。 |
\nolinkurl{...} | 部分可用 | 被报告为未知命令;网址作为普通文字保留。 |
\hypersetup{...} | 被略去 | 颜色、边框和 PDF 元数据设置都会被忽略。 |
\hyperlink{name}{text}, \hypertarget{name}{text} | 部分可用 | 文字保留;不生成链接。 |
\texorpdfstring{tex}{pdf} | 可用 | 使用第一个参数。 |
很长的网址
很长的 \url 可以在行尾的 / 等字符处断开,所以不会伸进页边距。不会在单词中间断开;如果网址仍然太长,请缩短它,或者使用带简短文字的 \href。
行尾的长网址
The full record, including every measurement, is kept at
\url{https://example.com/archive/2024/measurements/series-44/final/index.html}.与 TeX 发行版的区别
关于这个宏包,请参阅 hyperref。完整手册可在 CTAN 上找到:hyperref 和 url。
常见问题
如何在 LaTeX 中插入超链接?
加载 hyperref,然后写 \href{https://example.com}{link text}。要按原样显示网址,请写 \url{https://example.com}。
如何在 LaTeX 中把链接设为蓝色?
在 TeX 发行版中,用 \hypersetup{colorlinks=true, urlcolor=blue} 即可。Scissor LaTeX 在普通文档中会忽略这些设置,所以链接在那里看起来和普通文字一样,但在 PDF 中仍然可以点击。
网址中的下划线需要转义吗?
在 \url{...} 中或 \href 的第一个参数中不需要。两者都会按原样接受 _、%、# 和 ~。
本页的每个示例都在构建网站时由 Scissor LaTeX 排版。 最后更新:2026-11-07