LaTeX 超链接 您所在的位置:网站首页 超链接的链接名称是什么 LaTeX 超链接

LaTeX 超链接

2024-03-14 21:04| 来源: 网络整理| 查看: 265

原  文:Hyperlinks 译  者:Xovee 翻译时间:2021年7月27日

LaTeX Hyperlinks 超链接

除了打印文档,用户经常使用 PDF 浏览器来阅读文档。本文介绍如何在文档中生成超链接,以及如何将文档设置在 PDF 浏览器中进行阅读。

文章目录 LaTeX Hyperlinks 超链接介绍样式和颜色链接网址链接本地文件手动插入链接与 PDF 有关的选项参考指南链接样式选项PDF 选项

介绍

我们首先来看一个简单的例子,引入hyperref包,文档中所有的交叉引用模块都变成了超链接:

\documentclass{book} \usepackage{blindtext} \usepackage{hyperref} \title{Example of Hyperlinks} \author{Overleaf} \begin{document} \frontmatter \tableofcontents \clearpage \addcontentsline{toc}{chapter}{Foreword} {\huge {\bf Foreword}} \Blindtext \clearpage \addcontentsline{toc}{chapter}{Dummy entry} {\huge {\bf Dummy entry}} \Blindtext \mainmatter \chapter{First Chapter} This will be an empty chapter \begin{equation} \label{eq:1} \sum_{i=0}^{\infty} a_i x^i \end{equation} The equation \ref{eq:1} shows a sum that is divergent. This formula will be used later on page \pageref{second}. \Blindtext \clearpage \section{Second section} \label{second} \blindtext \Blinddocument \end{document}

在这里插入图片描述 只需要简单地在文档的 preamble 中引入\usepackage{hyperref},上面的例子中的目录文字就变成了超链接,点击即可跳转到对应的章节。

一般来说,hyperref包是你应该引入的最后一个包。当然,这个规则可能也有例外。

样式和颜色

你可以更改链接默认的样式来增强文档的可读性。请看下面这个例子:

\documentclass{book} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan, pdftitle={Overleaf Example}, pdfpagemode=FullScreen, } \urlstyle{same} \begin{document} \tableofcontents \chapter{First Chapter} This will be an empty chapter and I will put some text here \begin{equation} \label{eq:1} \sum_{i=0}^{\infty} a_i x^i \end{equation} The equation \ref{eq:1} shows a sum that is divergent. This formula will later be used in the page \pageref{second}. For further references see \href{http://www.overleaf.com}{Something Linky} or go to the next url: \url{http://www.overleaf.com} or open the next file \href{run:./file.txt}{File.txt} It's also possible to link directly any word or \hyperlink{thesentence}{any sentence} in your document. \end{document}

在这里插入图片描述 在这里插入图片描述 这是一个完整的例子。我们接下来详细地解释它是如何起作用的。

\hypersetup{…} 在这个命令中设置你想要的参数。每个参数必须用逗号分割,语法为parameter=value

\colorlinks=true 链接将会有颜色,默认是红色。

\linkcolor=blue 内部链接,那些由交叉引用生成的链接将会变为蓝色(blue)

\filecolor=magenta 链接到本地文件的链接将会变为洋红色(magenta)。

\urlcolor=cyan 链接到网站的链接将会变为蓝绿色(cyan)。

\urlstyle{same} 默认的样式为等宽字体。这个命令将会设置链接的字体样式与正文的字体样式相同。

链接网址

显示的网址或者邮件链接可以通过命令\url创建。你也可以使用\href命令来创建一个拥有显示文字和隐式地址的链接。

For further references see \href{http://www.overleaf.com}{Something Linky} or go to the next url: \url{http://www.overleaf.com}

在这里插入图片描述 现在介绍这两个命令:

\href{http://www.overleaf.com}{Something Linky} 第一个参数是需要链接的地址,第二个参数是实际显示的文字。

\url{http://www.overleaf.com} 该命令直接显示链接地址。

链接本地文件

\href和\url命令还可以用于链接本地文件。

For further references see \href{http://www.overleaf.com}{Something Linky} or go to the next url: \url{http://www.overleaf.com} or open the next file \href{run:./file.txt}{File.txt}

在这里插入图片描述 命令\href{run:./file.txt}{File.txt}会输出文字File.txt,点击文字会链接到本地的文件file.txt(相对当前工作目录)。注意路径中开头的run:。

文件路径遵从传统的 UNIX 习惯。.代表着当前目录,..代表着上一级目录。

你也可以使用命令\url。但是它可能会导致一些问题。

手动插入链接

我们前面提到,引入\hyperref包的时候,所有的交叉引用模块都会变成超链接。所以我们可以使用\label引用这些模块来创建超链接。这并不是唯一的手动插入链接的方法。

It's also possible to link directly any word or \hyperlink{thesentence}{any sentence} in you document. If you read this text, you will get no information. Really? Is there no information? For instance \hypertarget{thesentence}{this sentence}.

创建用户自定义的超链接主要有两个命令:

\hypertarget{thesentence}{this sentence} 第一个参数是该句子的唯一定位符。第二个参数是要引用的文字。该文字的样式取决于anchorcolor值。当用户点击指向该文字的超链接,那么页面就会跳转到文字所在的地方。

\hyperlink{thesentence}{any sentence} 这个命令输出可点击的文字any sentence,并将用户页面跳转到唯一定位符thesentence所在的页面。

与 PDF 有关的选项

我们创建的链接会显示在 PDF 文件之中,这毫无疑问。我们可以对生成的 PDF 文件添加更多的信息,改变 PDF 浏览器显示 PDF 的方式。例如:

\hypersetup{ colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan, pdftitle={Overleaf Example}, pdfpagemode=FullScreen, }

在这里插入图片描述 命令\hypersetup接收许多额外的参数来设置最终的 PDF 文件。

pdftitle={Overleaf Example} 文件的标题。

pdfpagemode=FullScreen 全屏(full screen)显示文件。

文末列出了\hypersetup所有可用的选项。

参考指南 链接样式选项 选项默认值描述hyperindextrue将索引表中的页码变为超链接linktocpagefalse将目录中的页码而不是文字变为超链接breaklinksfalse允许链接位于不同的行中colorlinksfalse给链接文字进行着色。这些颜色在打印的文档中依然会显示linkcolorred默认的内部链接颜色anchorcolorblack默认的锚点颜色citecolorgreen默认的参考文献引用颜色filecolorcyan默认的本地文件链接颜色urlcolormagenta默认的网址链接颜色frenchlinksfalse链接使用小型大写字母,不使用颜色 PDF 选项 选项默认值描述bookmarkstrueAcrobat书签将会启用,其与目录类似bookmarksopenfalse所有层级的书签都会显示citebordercolor0 1 0将引用的边框的颜色设置为0 1 0(RGB格式)filebordercolor同上linkbordercolor同上menubordercolor同上urlbordercolor同上pdfpagemodeempty设置文件打开的方式。可选项包括:UseThumbs (Thumbnails)和UseOutlines(bookmark)以及FullScreen。pdftitle设置文档的标题pdfauthor设置文档的作者pdfstartpage1设置 PDF 文件默认打开的页面位置


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有