使用 \LaTeX 编写文章,其中比较重要且常用的就是交叉引用。
定义
交叉引用是文章内的一种超链接,它能够从文章当前页面跳转到指定页面。
交叉引用用处颇多,在引用文章内图片,表格或者某一章节,段落以及参考文献等方面极为强大,能够方便读者查阅。
在Word等软件中,定义交叉引用比较麻烦。一方面需要给图片,表格编号并设置指向引用,另一方面它不像 \LaTeX 那样灵活,而是受限于指定的操作(比如入口,设置等过于复杂)。而 \LaTeX 就比较简单,只需要在被引用位置加入标记代码,就可以在文章内引用了。具体的使用方法下面讲述。
使用方法
首先需要引用宏包:\usepackage{hyperref}
在被引用的地方放置标签:\label{your label name}
在引用位置使用引用代码:\ref{your label name}
或\refname{your label name}
!编译文件时最好编译两次以上!
文章,段落
在section
或subsection
后面放置标签。
示例:
\section{这是章节}
\subsection{介绍}\label{sec:introduction}
\subsection{第一节}\label{sec:1}
\subsection{第二节}\label{part 2}
在\ref{sec:introduction}中我们首先对该章节进行介绍,在\refname{sec:1}和\ref{part 2}{111} 中我们讲述了两个重要极限的定义。
输出结果:
读者可自行尝试,发现使用ref编译一次会显示??而编译两次就能正常显示。这是由于 \LaTeX 在编译时,第一次保存了label标签,第二次才能被ref检索到,因此需要编译两次。
ref
编译的交叉引用会自动给你编号,比如我引用了第一章第一小节的内容,编译出来为1.1,并且可以点击
而refname
编译的内容是label
标签的全部内容,且不可点击。而且ref不支持形如\ref{}{}的自定义显示文字。
如果想要ref
自定义显示文字需要手动增加指令。
图片
对图片交叉引用,需要将label放在\end{figure}之前,以及使用\caption{}表示图片名称。
示例代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{ctex}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{favicon.png}
\caption{本网站的 Logo。}
\label{fig:logo}
\end{figure}
图 \ref{fig:logo} 是网站(https://math-enthusiast.top)的 Logo。
\end{document}
示例输出:
表格
和图片类似,表格需要在table后和tabular前插入\caption
和\label
标签。
\begin{table}[htbp]
\centering
\caption{示例表格}
\label{tab:t1}
\begin{tabular}{ccc}
\toprule
A & B & C\\
\midrule
1 & 2 & 3 \\
1.2 & 3.4 & 5.6 \\
\bottomrule
\end{tabular}
\end{table}
表\ref{tab:t1}是一个示例表格,使用ref命令可以引用该表。
示例输出:
参考文献
当参考文献较少,有精力一条一条修改时,推荐使用\thebibliography
例如:
\begin{thebibliography}{99}
\bibitem{ref1} Zheng L, Wang S, Tian L, et al., Query-adaptive late fusion for image search and person re-identification, Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 2015: 1741-1750
\bibitem{ref2} Arandjelović R, Zisserman A, Three things everyone should know to improve object retrieval, Computer Vision and Pattern Recognition (CVPR), 2012 IEEE Conference on, IEEE, 2012: 2911-2918
\end{thebibliography}
自定义颜色和文字
\hypersetup{
colorlinks=true, % 激活链接颜色
linkcolor=blue, % 文档内部链接颜色,适用于图、表在文中的引用
citecolor=blue, % 文献引用链接颜色,适用于文中参考文献引用
urlcolor=blue % 外部URL链接颜色,适用于参考文献添加超链接
}
脚注
在 LaTeX 中,脚注用于在页面底部添加注释。脚注的主要命令是 \footnote
,它有两种形式:
\footnote{text}
:在文档中插入一个上标数字,并在页面底部插入对应的脚注内容。\footnote[number]{text}
:使用指定的数字作为脚注标号,并在页面底部插入对应的脚注内容。