跳到主要内容

引用和参考文献

学术写作中,准确的引用和规范的参考文献是不可或缺的部分。LaTeX 提供了强大的交叉引用和参考文献管理功能,能够自动处理编号、排序和格式化,大大提高了写作效率。本章将详细介绍这些功能的使用方法和最佳实践。

交叉引用

引用系统的工作原理

LaTeX 的交叉引用系统基于两阶段处理:

  1. 第一遍编译:遇到 \label 时,LaTeX 将标签和对应的编号写入辅助文件(.aux
  2. 第二遍编译:遇到 \ref 时,LaTeX 从辅助文件读取编号并插入文档

这就是为什么需要多次编译的原因——第一次编译后引用会显示为 ??,第二次编译才会正确显示。

定义标签

\label 命令定义一个引用点:

\section{引言}
\label{sec:intro}

\begin{figure}
\includegraphics{image.png}
\caption{示例图片}
\label{fig:example}
\end{figure}

\begin{table}
\caption{数据统计}
\label{tab:stats}
\end{table}

\begin{equation}
E = mc^2
\label{eq:einstein}
\end{equation}

标签命名约定

前缀用途示例
sec:章节sec:intro, sec:method
fig:图片fig:architecture
tab:表格tab:results
eq:公式eq:momentum
lst:代码lst:algorithm
ch:ch:background

这种命名约定让你的源文件更易读,也方便批量处理。

标签位置的关键性

标签的位置决定了引用的编号:

% 正确:标签紧跟标题
\section{方法}
\label{sec:method}

% 错误:标签在标题之前
\label{sec:method}
\section{method}

% 对于浮动体,标签必须在 \caption 之后
\begin{figure}
\includegraphics{image.png}
\caption{图片标题}
\label{fig:example} % 必须在 caption 之后
\end{figure}

原因\caption 命令会增加计数器的值,如果 \label 放在 \caption 之前,引用的编号会比实际编号小 1。

基本引用命令

% 引用编号
\ref{sec:intro} % 输出:1

% 引用页码
\pageref{sec:intro} % 输出:5

公式引用

使用 amsmath 宏包的 \eqref 引用公式,自动添加括号:

\usepackage{amsmath}

公式~\eqref{eq:einstein} 描述了质能关系。
% 输出:公式 (1) 描述了质能关系。

% 对比普通 \ref
公式~\ref{eq:einstein}
% 输出:公式 1 描述了质能关系。

智能引用(cleveref)

cleveref 宏包自动添加引用类型名称:

\usepackage{cleveref}

\cref{sec:intro} % 输出:第 1 节
\cref{fig:example} % 输出:图 1
\cref{tab:stats} % 输出:表 1
\cref{eq:einstein} % 输出:公式 (1)

% 句首大写形式
\Cref{sec:intro} % 输出:第 1 节

% 多引用
\cref{fig:a,fig:b,fig:c} % 输出:图 1-3

% 引用范围
\crefrange{fig:a}{fig:c} % 输出:图 1~3

% 自定义名称
\crefname{figure}{图}{图}
\Crefname{figure}{图}{图}

引用格式最佳实践

% 推荐:使用波浪号连接编号和前文
如图~\ref{fig:example} 所示...

% 推荐:使用 intelligent 引用
如\cref{fig:example} 所示...

% 避免:直接连接
如图\ref{fig:example}所示 % 可能产生错误的断行

参考文献管理

手动方式(thebibliography)

适合小型文档或参考文献很少的情况:

参考文献 \cite{knuth1984}。

\begin{thebibliography}{99}
\bibitem{knuth1984}
Knuth D. E.
\textit{The TeXbook}.
Addison-Wesley, 1984.

\bibitem{lamport1994}
Lamport L.
\textit{\LaTeX: A Document Preparation System}.
Addison-Wesley, 2nd edition, 1994.
\end{thebibliography}

参数说明{99} 表示最多两位数的引用编号,根据参考文献数量调整。

BibTeX 方式

BibTeX 是传统的参考文献管理方式,将文献信息与文档分离。

创建 BibTeX 文件references.bib):

@book{knuth1984,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
year = {1984},
isbn = {0-201-13447-0}
}

@article{einstein1905,
author = {Einstein, Albert},
title = {On the Electrodynamics of Moving Bodies},
journal = {Annalen der Physik},
year = {1905},
volume = {17},
pages = {891--921}
}

@inproceedings{vaswani2017,
author = {Vaswani, Ashish and Shazeer, Noam and others},
title = {Attention Is All You Need},
booktitle = {Advances in Neural Information Processing Systems},
year = {2017},
volume = {30},
pages = {5998--6008}
}

@online{overleaf2024,
author = {{Overleaf Team}},
title = {Bibliography Management with {BibTeX}},
year = {2024},
url = {https://www.overleaf.com/learn/latex/Bibliography_management_with_BibTeX},
urldate = {2024-01-15}
}

在文档中使用

\documentclass{article}

\begin{document}

引用 \cite{knuth1984} 和 \cite{einstein1905}。

\bibliographystyle{plain}
\bibliography{references}

\end{document}

编译流程

pdflatex document    # 生成 .aux 文件
bibtex document # 处理参考文献
pdflatex document # 更新引用
pdatex document # 确保所有引用正确

BibTeX 条目类型

类型用途必需字段
@article期刊论文author, title, journal, year
@book书籍author/editor, title, publisher, year
@inproceedings会议论文author, title, booktitle, year
@incollection书籍章节author, title, booktitle, publisher, year
@phdthesis博士论文author, title, school, year
@mastersthesis硕士论文author, title, school, year
@techreport技术报告author, title, institution, year
@online网络资源author, title, url, year

BibTeX 样式

样式说明
plain按字母顺序排列,数字编号
abbrv缩写格式,按字母顺序
alpha标签为作者姓名首字母+年份
unsrt按引用顺序排列
ieeetrIEEE 格式
acmACM 格式
apaAPA 格式

natbib 宏包

natbib 提供更灵活的引用方式:

\usepackage{natbib}

\citet{knuth1984} % Knuth (1984)
\citep{knuth1984} % (Knuth, 1984)
\citet*{knuth1984} % Knuth, Donald E. (1984)
\citep[p.~10]{knuth1984} % (Knuth, 1984, p. 10)
\citeauthor{knuth1984} % Knuth
\citeyear{knuth1984} % 1984

BibLaTeX 方式

BibLaTeX 是现代的参考文献解决方案,功能更强大,更易定制。

基本配置

\usepackage[
backend=biber, % 使用 Biber 后端
style=numeric, % 引用样式
sorting=none, % 按引用顺序排序
]{biblatex}

\addbibresource{references.bib} % 加载文献库

\begin{document}

引用 \cite{knuth1984}。

\printbibliography % 打印参考文献

\end{document}

编译流程

xelatex document    # 生成 .bcf 文件
biber document # Biber 处理文献
xelatex document # 更新引用
xelatex document # 确保正确

引用样式选择

% 数字编号样式
\usepackage[style=numeric, backend=biber]{biblatex} % [1]
\usepackage[style=numeric-comp, backend=biber]{biblatex} % [1-3]

% 作者-年份样式
\usepackage[style=authoryear, backend=biber]{biblatex} % (Smith 2020)

% 领域专用样式
\usepackage[style=ieee, backend=biber]{biblatex} % IEEE
\usepackage[style=apa, backend=biber]{biblatex} % APA
\usepackage[style=chicago-authordate, backend=biber]{biblatex}

中文参考文献

使用 biblatex-gb7714 符合中国国家标准:

\usepackage[
backend=biber,
style=gb7714-2015,
gbpub=false,
]{biblatex-gb7714}

高级引用命令

\cite{knuth1984}                  % [1]
\parencite{knuth1984} % (Knuth, 1984)
\textcite{knuth1984} % Knuth [1]
\footcite{knuth1984} % 脚注引用
\fullcite{knuth1984} % 完整引用信息

% 带页码
\cite[页~42]{knuth1984} % [1, 页 42]

% 仅作者或年份
\citeauthor{knuth1984} % Knuth
\citeyear{knuth1984} % 1984

分类参考文献

% 定义分类
\DeclareBibliographyCategory{primary}
\DeclareBibliographyCategory{secondary}

% 添加条目到分类
\addtocategory{primary}{knuth1984, lamport1994}

% 分别输出
\printbibliography[category=primary, title={主要参考文献}]
\printbibliography[category=secondary, title={次要参考文献}]

按类型输出

\printbibliography[type=article, title={期刊论文}]
\printbibliography[type=book, title={书籍}]
\printbibliography[type=inproceedings, title={会议论文}]

超链接

hyperref 宏包

hyperref 宏包让文档中的链接可点击:

\usepackage{hyperref}

% 外部链接
\href{https://www.example.com}{链接文本}
\url{https://www.example.com}

% 内部链接
\hyperref[sec:intro]{跳转到引言}

% 邮件链接
\href{mailto:[email protected]}{发送邮件}

配置选项

\usepackage[
colorlinks=true, % 使用彩色链接而非边框
linkcolor=blue, % 内部链接颜色
filecolor=magenta, % 文件链接颜色
urlcolor=cyan, % URL 颜色
citecolor=green, % 引用链接颜色
pdfauthor={作者姓名}, % PDF 元数据
pdftitle={文档标题},
pdfsubject={主题},
pdfkeywords={关键词},
]{hyperref}

与引用配合

hyperref 会自动让交叉引用和参考文献引用变为可点击链接:

\usepackage{hyperref}

如图~\ref{fig:example} 所示... % 点击可跳转到图片
详见文献 \cite{knuth1984}。 % 点击可跳转到参考文献条目

脚注

基本脚注

这是正文内容\footnote{这是脚注内容}。

脚注格式

% 符号脚注
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

% 字母脚注
\renewcommand{\thefootnote}{\alph{footnote}}

% 罗马数字
\renewcommand{\thefootnote}{\roman{footnote}}

分离标记和内容

正文内容\footnotemark。

\footnotetext{脚注内容放在其他地方。}

索引

创建索引

\usepackage{makeidx}
\makeindex

\begin{document}

关键词\index{关键词}
子条目\index{关键词!子条目}
参见\index{关键词|see{相关词}}

\printindex

\end{document}

编译索引

xelatex document
makeindex document
xelatex document

词汇表

使用 glossaries 宏包

\usepackage{glossaries}
\makeglossaries

\newglossaryentry{latex}{
name=LaTeX,
description={一种文档排版系统}
}

\begin{document}

使用 \gls{latex} 进行排版。

\printglossaries

\end{document}

编译词汇表

xelatex document
makeglossaries document
xelatex document

常见问题与解决方案

引用显示 ??

原因:标签未定义或首次编译。

解决:多次编译,检查 \label 是否存在。

引用编号错误

原因\label 位置错误,如放在 \caption 之前。

解决:将 \label 放在 \caption 之后。

参考文献不显示

原因:未运行 BibTeX/Biber,或文件路径错误。

解决

xelatex document
biber document # 或 bibtex document
xelatex document
xelatex document

链接颜色冲突

原因:多个宏包修改链接颜色。

解决hyperref 应该最后加载:

\usepackage{其他宏包}
\usepackage{hyperref} % 最后加载

完整示例

\documentclass[UTF8]{ctexart}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[
backend=biber,
style=numeric-comp,
sorting=none,
]{biblatex}
\addbibresource{references.bib}
\usepackage[
colorlinks=true,
linkcolor=blue,
citecolor=blue,
urlcolor=blue,
]{hyperref}
\usepackage{cleveref}

\title{交叉引用与参考文献示例}
\author{作者}
\date{\today}

\begin{document}

\maketitle

\section{引言}
\label{sec:intro}

本文介绍 LaTeX 的引用功能,详见\Cref{sec:method}。

\section{研究方法}
\label{sec:method}

如\Cref{fig:example} 所示,公式~\eqref{eq:example} 描述了基本关系。

\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{example.png}
\caption{示例图片}
\label{fig:example}
\end{figure}

\begin{equation}
E = mc^2
\label{eq:example}
\end{equation}

更多细节参见文献 \cite{knuth1984, lamport1994}。

\printbibliography

\end{document}

编译:

xelatex document
biber document
xelatex document
xelatex document

小结

本章详细介绍了 LaTeX 的引用系统:

  • 交叉引用\label\ref 的工作原理和使用方法
  • 智能引用:cleveref 宏包的便捷引用
  • 参考文献:BibTeX 和 BibLaTeX 两种管理方式
  • 引用样式:不同学科领域的引用格式
  • 超链接:hyperref 宏包的配置和使用
  • 脚注、索引、词汇表:辅助引用功能
  • 常见问题:引用错误的排查和解决

掌握引用和参考文献管理是学术写作的基本技能,可以让你的论文更加规范和专业。