30分钟快速上手LaTex

30 分钟快速上手 LATEX

1.什么是LATEX?

LATEX(发音为LAY-tek或LAH-tek)是一种用于排版专业文档的工具。然而,LaTeX的操作模式与你可能使用过的许多其他文档制作应用程序(如Microsoft Word或LibreOffice Writer)有很大的不同:这些“所见即所得”的工具为用户提供了一个交互式页面,用户可以在其中输入和编辑文本,并应用各种样式。LaTeX的工作方式非常不同:你的文档是一个纯文本文件,其中散布着LaTeX命令,用于表达所需的(排版)结果。为了生成一个可见的、排版好的文档,你的LaTeX文件由一个叫做TeX engine的软件处理,它使用嵌入在文本文件中的命令来指导和控制排版过程,将LaTeX命令和文档文本转换为专业排版的PDF文件。这意味着你只需要关注文档的内容,计算机通过LaTeX命令和TeX引擎会处理视觉外观(格式化)。

2.为什么学习LATEX?

  • 支持排版极其复杂的数学、表格和物理科学的技术内容;
  • 提供脚注、交叉参考和书目管理的设施;
  • 易于生成复杂或冗长的文档元素,如索引、词汇表、目录、图表;
  • 由于其内在的可编程性和通过数千个免费附加包的可扩展性,因此可以高度定制,用于定制文档的制作。

LATEX的一个重要好处是文档内容和文档样式的分离:一旦你写好了文档的内容,它的外观就可以很容易地改变。类似地,你可以创建一个LATEX文件来定义特定文档类型的布局/风格,该文件可以用作模板,以标准化该类型其他文档的创作/制作;例如,它允许科学出版商用LATEX创建文章模板,作者用LATEX写论文提交给期刊。Overleaf有一个包含数千个模板的图库,涵盖了大量的文档类型——从科学文章、报告和书籍到简历和演示文稿。因为这些模板定义了文档的布局和样式,所以作者只需要在overleaf中打开它们(创建一个新项目),然后开始编写代码添加内容。

3.编写第一个LATEX程序

第一步是创建一个新的LATEX项目。你可以在自己的电脑上创建一个新的.tex文件;或者可以在Overleaf中启动一个新项目

\documentclass{article}
\begin{document}
First document. This is a simple example, with no 
extra parameters or packages included.
\end{document}

第一行代码\documentclass{article}声明文档类型,即它的类,它控制文档的整体外观。不同类型的文件需要不同的类;也就是说,一份简历需要一个不同的类别,而一篇科学论文可能使用标准的LATEX文章类别。您可能正在处理的其他类型的文档可能需要不同的类,例如book或report。要了解许多可用的LATEX类类型,请访问CTAN(综合TeX存档网络)上的相关页面。

设置文档类后,我们的内容,即文档的主体部分,写在 \begin{document}\end{document} 标签之间。在打开上面的示例后,您可以对文本进行更改,完成后,通过重新编译文档来查看生成的排版 PDF。在 Overleaf 中,只需点击重新编译,如下所示:

在这里插入图片描述

任何Overleaf项目都可以配置为每次编辑时自动重新编译:单击“重新编译”按钮旁边的小箭头,并将“自动编译”设置为“打开”,如下面的截图所示:

在这里插入图片描述

4.LATEX文档的序言

Overleaf将LATEX文档存储为一个名为main.tex的文件。

在 \begin{document} 命令之前出现在你的 .tex 文件中的所有内容被称为序言部分,它充当文档的“设置”部分。在导言部分中,你定义文档类(类型),以及诸如编写文档时要使用的语言等具体内容;加载你希望使用的包,并在其中应用其他类型的配置。

一个最小的文档序言示例:

\documentclass[12pt, letterpaper]{article}
\usepackage{graphicx}

其中 \documentclass[12pt, letterpaper]{article} 定义了文档的整体类(类型)。额外的参数必须用逗号分隔,并包含在方括号([…])中,用于配置基于 article 类的此文档实例;即,我们希望为这个特定的基于 article 类的文档使用的设置。在本例中,这两个参数的作用为:12pt设置字体大小,letterpaper设置纸张的大小。(当然,也可以使用其他字体大小,如9pt、11pt、12pt,但如果没有指定,则默认大小为10pt。至于纸张大小,其他可能的值是a4纸和legalpaper。有关更多信息,请参阅有关页面大小和页边距的文档

序言行 \usepackage{graphicx} ,是加载外部包(这里是graphicx)以扩展LATEX的功能,使其能够导入外部图形文件的示例。

5.LATEX文档的标题、作者和日期信息

在文档中添加标题、作者和日期需要在序言中增加三行(而不是文档的主体)。这些行是:

  • \title{My first LaTeX document}:文档的题目。
  • \author{Hubert Farnsworth}:作者的名字。
    • \thanks{Funded by the Overleaf team.}:可以添加在author命令的大括号内的作者名之后。它将在大括号内添加一个上标和一个脚注。如果你需要在你的文章中感谢一个机构,这很有用。
  • \date{August 2024}:可以手动输入日期或使用命令\today在每次编译文档时设置当前日期。

加上这些行,你的序言应该是这样的:

\documentclass[12pt, letterpaper]{article}
\title{My first LaTeX document}
\author{Hubert Farnsworth\thanks{Funded by the Overleaf team.}}
\date{August 2022}

排版标题、作者和日期信息到文档中,请在文档的正文部分使用 \maketitle 命令:

\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
\end{document}

序言部分和正文部分现在可以合并成一份完整的文件。

\documentclass[12pt, letterpaper]{article}
\title{My first LaTeX document}
\author{Hubert Farnsworth\thanks{Funded by the Overleaf team.}}
\date{August 2022}
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
\end{document}

在这里插入图片描述

6.LATEX文档的注释

LaTeX 是一种“程序代码”的形式,但专门用于文档排版;因此,与使用任何其他编程语言编写的代码一样,在文档中包含注释非常有用。 LaTeX 注释是文本的一部分,不会被排版或以任何方式影响文档 - 通常用于添加“待办事项”注释;包括解释性说明;提供关于复杂宏的内联解释,或在调试时注释掉行/段落的 LaTeX 代码。

在 LaTeX 中添加注释,只需在行首写一个 % 符号,如下所示的代码使用了上面的示例:

\documentclass[12pt, letterpaper]{article}
\title{My first LaTeX document}
\author{Hubert Farnsworth\thanks{Funded by the Overleaf team.}}
\date{August 2022}
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!

% This line here is a comment. It will not be typeset in the document.
\end{document}

在overleaf中打开查看效果

7.LATEX文档的粗体、斜体和下划线

接下来,我们将看一些文本格式化命令:

  • 粗体:在 LaTeX 中使用 \textbf{…} 命令进行粗体排版。
  • 斜体:使用 \textit{…} 命令生成斜体文本。
  • 下划线:要给文本添加下划线,请使用 \underline{…} 命令。
Some of the \textbf{greatest}
discoveries in \underline{science} 
were made by \textbf{\textit{accident}}.

在overleaf中打开查看效果
在这里插入图片描述
另一个非常有用的命令是 \emph{argument},其对 argument 的影响取决于上下文。在普通文本中,强调的文本会被斜体化,但如果在斜体文本中使用,则行为相反 - 请参见下一个示例:

Some of the greatest \emph{discoveries} in science 
were made by accident.

\textit{Some of the greatest \emph{discoveries} 
in science were made by accident.}

\textbf{Some of the greatest \emph{discoveries} 
in science were made by accident.}

在overleaf中打开查看效果
在这里插入图片描述
【注意】一些包,比如 Beamer,会改变 \emph 命令的行为。

8.LATEX文档中添加图片

在本节中,我们将看一下如何将图片添加到 LaTeX 文档中。Overleaf 支持三种方式插入图片:

  • 使用编辑器工具栏上的“插入图像”按钮(位于编辑器工具栏上),将图像插入到可视编辑器或代码编辑器中。

    image-20240218173924996

  • 将图像复制并粘贴到可视编辑器或代码编辑器中。

  • 使用代码编辑器编写插入图形的 LaTeX 代码。

选项 1 和 2 会自动生成插入图像所需的 LaTeX 代码,但在这里我们介绍选项 3 - 请注意,您需要将这些图像上传到您的 Overleaf 项目中。以下示例演示了如何包含一张图片:

\documentclass{article}
\usepackage{graphicx} %LaTeX package to import graphics
\graphicspath{{images/}} %configuring the graphicx package
 
\begin{document}
The universe is immense and it seems to be homogeneous, 
on a large scale, everywhere we look.

% The \includegraphcs command is 
% provided (implemented) by the 
% graphicx package
\includegraphics{universe}  
 
There's a picture of a galaxy above.
\end{document}

在overleaf中打开查看效果
在这里插入图片描述
将图形导入到 LaTeX 文档中需要一个附加的包,它提供了包含外部图形文件所需的命令和功能。上面的示例加载了 graphicx 包,其中包含许多其他命令,包括 \includegraphics{...} 用于导入图形和 \graphicspath{...} 用于告诉 LaTeX 图形的位置在哪里。

在示例中,命令 \graphicspath{{images/}} 告诉 LaTeX 图像保存在名为 images 的文件夹中,该文件夹包含在当前目录中。

\includegraphics{universe} 命令实际上执行了将图像插入文档的工作。在这里,universe 是图像文件的名称,但没有扩展名。

【注意】

  • 虽然在 \includegraphics 命令中允许使用包括扩展名在内的完整文件名,但最佳实践是省略文件扩展名,因为这将促使 LaTeX 搜索所有支持的格式。
  • 通常,图形文件的文件名不应包含空格或多个点;在将图像文件上传到 Overleaf 时,建议使用小写字母的文件扩展名

9.LATEX中对图像进行标注、标签化和引用

可以使用 figure 环境对图像进行标注、标签化和引用,如下所示:

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{images/}}
 
\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.75\textwidth]{mesh}
    \caption{A nice plot.}
    \label{fig:mesh1}
\end{figure}
 
As you can see in figure \ref{fig:mesh1}, the function grows near the origin. This example is on page \pageref{fig:mesh1}.

\end{document}

在overleaf中打开查看效果

在这里插入图片描述

在示例中有几个值得注意的命令:

  • \includegraphics[width=0.75\textwidth]{mesh}:这种形式的 \includegraphics 命令指示 LaTeX 将图形的宽度设置为文本宽度的 75% - 文本宽度的值存储在 \textwidth 命令中。
  • \caption{A nice plot.}:顾名思义,此命令设置了图形的标题,可以放在图形上方或下方。如果您创建了一个图表列表,这个标题将在列表中使用。
  • \label{fig:mesh1}:使用 \label 命令给这个图像设置一个标签,以便在文档中引用它。标签用于生成图像的编号,并与下一个命令结合使用,使您能够引用它。
  • \ref{fig:mesh1}:此代码将被替换为所引用图形对应的编号。

包含在LATEX文档中的图像应该放置在figure环境或类似环境中,以便LATEX可以自动将图像定位到文档中的合适位置。


进阶教程参考如下:

10.在LATEX中创建列表

可以使用环境创建不同类型的列表,环境用于封装实现特定排版特性所需的 LaTeX 代码。一个环境以 \begin{environment-name} 开始,以 \end{environment-name} 结束,其中 environment-name 可能是 figure、tabular 或其中一个列表类型:itemize 用于无序列表,enumerate 用于有序列表。

10.1无序列表

无序列表由 itemize环境生成。每个列表条目之前必须加上\item命令,如下所示:

\documentclass{article}
\begin{document}
\begin{itemize}
  \item The individual entries are indicated with a black dot, a so-called bullet.
  \item The text in the entries may be of any length.
\end{itemize}
\end{document}

在overleaf中打开查看效果

在这里插入图片描述

10.2有序列表

有序列表使用与无序列表具有相同的语法,但使用 enumerate 环境创建:

\documentclass{article}
\begin{document}
\begin{enumerate}
  \item This is the first entry in our list.
  \item The list numbers increase with each entry we add.
\end{enumerate}
\end{document}

在overleaf中打开查看效果
在这里插入图片描述


进阶教程参考如下:

11.在LATEX中添加数学表达式

LATEX的一个主要优点是易于编写数学表达式。LATEX为排版数学提供了两种书写模式:

  • 内联数学模式,用于编写作为段落一部分的公式。
  • 显示数学模式,用于编写不属于文本或段落的表达式,并且在单独的行上排版。

11.1内联数学模式

\documentclass[12pt, letterpaper]{article}
\begin{document}
In physics, the mass-energy equivalence is stated 
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.
\end{document}

在overleaf中打开查看效果
在这里插入图片描述
要排版行内模式数学,可以使用以下任一对定界符: \( ... \), $ ... $ or \begin{math} ... \end{math},如下面的示例所示:

\documentclass[12pt, letterpaper]{article}
\begin{document}
\begin{math}
E=mc^2
\end{math} is typeset in a paragraph using inline math mode---as is $E=mc^2$, and so too is \(E=mc^2\).
\end{document}

在overleaf中打开查看效果
在这里插入图片描述

11.2显示数学模式

在显示模式下排版的方程式可以编号也可以不编号,如下例所示:

\documentclass[12pt, letterpaper]{article}
\begin{document}
The mass-energy equivalence is described by the famous equation
\[ E=mc^2 \] discovered in 1905 by Albert Einstein. 

In natural units ($c = 1$), the formula expresses the identity
\begin{equation}
E=m
\end{equation}
\end{document}

在overleaf中打开查看效果
在这里插入图片描述
要设置显示模式数学,可以使用以下分隔符对之一: \[ ... \], \begin{displaymath} ... \end{displaymath} or \begin{equation} ... \end{equation}

历史上,排版显示模式数学需要使用$$字符分隔符,如$$ ... display math here ...$$,但不再推荐此方法。

11.3应用

\documentclass{article}
\begin{document}
Subscripts in math mode are written as $a_b$ and superscripts are written as $a^b$. These can be combined and nested to write expressions such as

\[ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} = T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) \]
 
We write integrals using $\int$ and fractions using $\frac{a}{b}$. Limits are placed on integrals using superscripts and subscripts:

\[ \int_0^1 \frac{dx}{e^x} =  \frac{e-1}{e} \]

Lower case Greek letters are written as $\omega$ $\delta$ etc. while upper case Greek letters are written as $\Omega$ $\Delta$.

Mathematical operators are prefixed with a backslash as $\sin(\beta)$, $\cos(\alpha)$, $\log(x)$ etc.
\end{document}

在overleaf中打开查看效果
在这里插入图片描述
下一个示例使用由amsmath包提供的equation*环境,因此我们需要在文档序言中添加以下行:

\usepackage{amsmath} % For the equation* environment

利用amsmath对齐等式教程

\documentclass{article}
\usepackage{amsmath}% For the equation* environment
\begin{document}
\section{First example}

The well-known Pythagorean theorem \(x^2 + y^2 = z^2\) was proved to be invalid for other exponents, meaning the next equation has no integer solutions for \(n>2\):

\[ x^n + y^n = z^n \]

\section{Second example}

This is a simple math expression \(\sqrt{x^2+1}\) inside text. 
And this is also the same: 
\begin{math}
\sqrt{x^2+1}
\end{math}
but by using another command.

This is a simple math expression without numbering
\[\sqrt{x^2+1}\] 
separated from text.

This is also the same:
\begin{displaymath}
\sqrt{x^2+1}
\end{displaymath}

\ldots and this:
\begin{equation*}
\sqrt{x^2+1}
\end{equation*}
\end{document}

在overleaf中打开查看效果
在这里插入图片描述

12.LATEX的基本文档结构

接下来,将探讨Abstracts以及如何将LATEX文档划分为不同的章节、节和段落。

12.1摘要

科学文章通常提供abstract,即对其核心主题或论点的简要overview/summary。下面的例子演示了如何使用LATEX的abstract环境来排版一个摘要:

\documentclass{article}
\begin{document}
\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}
\end{document}

在overleaf中打开查看效果
在这里插入图片描述

12.2段落和新行

摘要写好之后,我们就可以开始写第一段了。下一个示例演示:

  • 按下 “enter” 键两次会创建一个新的段落,结束当前行并插入一个空白行。
  • 要在不开始新段落的情况下开始新行,可以使用 \\ 命令插入手动换行,即双反斜杠;或者使用 \newline 命令。
\documentclass{article}
\begin{document}

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}

After our abstract we can begin the first paragraph, then press ``enter'' twice to start the second one.

This line will start a second paragraph.

I will start the third paragraph and then add \\ a manual line break which causes this text to start on a new line but remains part of the same paragraph. Alternatively, I can use the \verb|\newline|\newline command to start a new line, which is also part of the same paragraph.
\end{document}

在overleaf中打开查看效果
在这里插入图片描述
【注意】不建议使用多个\\\newline 来“模拟”段落之间具有较大间距的段落,因为这可能会干扰 LaTeX 的排版算法。推荐的方法是继续使用空行来创建新段落,而不使用任何\\,并通过在导言中添加 \usepackage{parskip} 来加载 parskip 包。


进阶教程参考如下:

12.3章节和节

较长的文档,无论使用何种创作软件,通常都被划分为部分(parts)、章节(chapters)、节(sections)、子节(subsections)等等。LaTeX还提供了文档结构命令,但是可用的命令及其实现取决于所使用的文档类。例如,使用book类创建的文档可以分成部分、章节、节、子节等等,但是letter类不支持任何这样做的命令。

下面的例子演示了基于book类构造文档的命令:

\documentclass{book}
\begin{document}

\chapter{First Chapter}

\section{Introduction}

This is the first section.

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit. Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\subsection{First Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem...
\end{document}

在overleaf中打开查看效果

在这里插入图片描述

各级节标题的命令基本上是自解释的;例如, \chapter{First Chapter} 创建一个名为 First Chapter章的新章节,\section{Introduction}生成一个名为Introduction的节,依此类推。节可以进一步细分为 \subsection{...},甚至 \subsubsection{...}。节、子节等的编号是自动的,但可以通过使用相应命令的所谓星号版本来禁用,该版本在命令末尾带有一个星号(*),例如 \section*{...}\subsection*{...}

总的来说,LaTeX文档类提供了以下分段命令,每个特定的类都支持一个相关的子集:

  • \part{part},部分
  • \chapter{chapter},章节
  • \section{section},节
  • \subsection{subsection},子节
  • \subsubsection{subsubsection},子小节
  • \paragraph{paragraph},段落
  • \subparagraph{subparagraph},子段落

有关章节和节的高级教程

13.在LATEX中创建表

13.1创建一个基本表

\begin{center}
\begin{tabular}{c c c}
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\  
 cell7 & cell8 & cell9    
\end{tabular}
\end{center}

在overleaf中打开查看效果
在这里插入图片描述tabular环境是创建表的默认LATEX方法。你必须为该环境指定一个参数,在本例中为{c c c},该参数建议LATEX将有三列,并且每列中的文本必须居中。您还可以使用r来对文本进行右对齐,使用l来对文本进行左对齐。对齐符号&用于分隔表行内的各个表单元格。要结束一个表行,使用新的行命令\\。我们的表包含在center环境中,使其在页面的文本宽度内居中。

13.2为表格添加边框

tabular环境支持水平线和垂直线(规则)作为表格的一部分:

  • 要在行上方和行下方添加水平规则,请使用\hline命令
  • 要在列之间添加垂直规则,请使用垂直线参数|

在这个例子中,参数是{|c|c|c|},它声明了三个(居中的)列,每个列由竖线(规则)分隔;此外,我们使用\hline在第一行上方和最后一行下方放置一条水平线:

\begin{center}
\begin{tabular}{|c|c|c|} 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end{tabular}
\end{center}

在overleaf中打开查看效果
在这里插入图片描述

\begin{center}
 \begin{tabular}{||c c c c||} 
 \hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
 \hline\hline
 1 & 6 & 87837 & 787 \\ 
 \hline
 2 & 7 & 78 & 5415 \\
 \hline
 3 & 545 & 778 & 7507 \\
 \hline
 4 & 545 & 18744 & 7560 \\
 \hline
 5 & 88 & 788 & 6344 \\ [1ex] 
 \hline
\end{tabular}
\end{center}

在overleaf中打开查看效果

在这里插入图片描述

在LATEX中创建表可能很耗时,因此使用TablesGenerator.com在线工具为表导出LATEX代码。

13.3LATEX中对表格进行标注、标签化和引用

可以用和图片差不多的方式给表格加上标题和引用。唯一的区别是,使用的不是figure环境,而是 table 环境。

Table \ref{table:data} shows how to add a table caption and reference a table.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||} 
 \hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
 \hline\hline
 1 & 6 & 87837 & 787 \\ 
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex] 
 \hline
\end{tabular}
\caption{Table to test captions and labels.}
\label{table:data}
\end{table}

在overleaf中打开查看效果
在这里插入图片描述

14.在LATEX中管理参考文献

在 LaTeX 中,当涉及到参考文献管理包时,有三个主要选择:bibtex、natbib 和 biblatex

本文解释了如何使用 biblatex 包来管理和格式化 LaTeX 文档中的参考文献。biblatex 是一个现代选项,用于处理参考文献信息,提供了比另外两个选项更简单、更灵活的接口,以及更好的语言本地化支持。

下面是 biblatex 包的一个最小工作示例:

\documentclass[letterpaper,10pt]{article}
\usepackage{biblatex} %Imports biblatex package
\addbibresource{sample.bib} %Import the bibliography file

\begin{document}
Let's cite! Einstein's journal paper \cite{einstein} and Dirac's
book \cite{dirac} are physics-related items. 

\printbibliography %Prints bibliography

\end{document}

在overleaf中打开查看效果

image-20240219200919225

在这个例子中有四个与文献相关的命令:

  • 使用 \usepackage{biblatex} 导入 biblatex 包。
  • 使用 \addbibresource{sample.bib} 导入参考文献数据文件 sample.bib,该文件包含了每个引用的书籍、文章等的信息。有关更多信息,请参阅参考文献文件部分
  • 使用 \cite{einstein} 命令在文档中插入一个引用[1],本例中对应一个参考文献条目,einstein是一个关键字,对应于sample.bib中的一个条目。
  • 使用 \printbibliography 打印出引用的参考文献列表,文章文档类的默认标题是”references“,书籍和报告的默认标题是“Bibliography”。

14.1参数的基本用法

可以向包导入命令传递几个参数,示例如下:

\documentclass{article}

\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt
]{biblatex}
\addbibresource{sample.bib}

\title{Bibliography management: \texttt{biblatex} package}
\author{Overleaf}
\date{ }

\begin{document}

\maketitle

Using \texttt{biblatex} you can display a bibliography divided 
into sections, depending on citation type. Let's cite! Einstein's 
journal paper \cite{einstein} and Dirac's book \cite{dirac} are 
physics-related items. Next, \textit{The \LaTeX\ Companion} book
 \cite{latexcompanion}, Donald Knuth's website \cite{knuthwebsite},
\textit{The Comprehensive Tex Archive Network} (CTAN) 
\cite{ctan} are \LaTeX-related items; but the others, Donald Knuth's items, 
\cite{knuth-fa,knuth-acp} are dedicated to programming. 

\medskip

\printbibliography

\end{document}

在overleaf中打开查看效果

在导入biblatex时,会添加一些额外的选项,在括号和逗号分隔内:

  • backend=biber,将后端设置为对参考文献进行排序,biber是默认的,推荐使用,因为它为几个命令提供了完整的本地化,并且biber的样式更容易修改,因为它们使用标准的LATEX宏。另一个支持的后端是bibtex,这是一个更传统的程序;如果设置为后端,则bibtex将仅用于对参考文献进行排序,因此此处不能使用bibtex样式。
  • style=alphabetic,定义参考文献样式和引文样式,在本例中为字母样式。根据风格的不同,可能会有更多的引用命令可用。有关更多信息,请参阅bibliatex参考文献样式引文样式
  • sorting=ynt,确定参考文献来源排序的标准。在本例中,它们按年份、姓名和头衔排序。有关排序选项列表,请参阅参考指南

14.2bibliography文件

参考文献文件必须具有标准的bibtex语法。

@article{einstein,
    author = "Albert Einstein",
    title = "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
    [{On} the electrodynamics of moving bodies]",
    journal = "Annalen der Physik",
    volume = "322",
    number = "10",
    pages = "891--921",
    year = "1905",
    DOI = "http://dx.doi.org/10.1002/andp.19053221004",
    keywords = "physics"
}

@book{dirac,
    title = {The Principles of Quantum Mechanics},
    author = {Paul Adrien Maurice Dirac},
    isbn = {9780198520115},
    series = {International series of monographs on physics},
    year = {1981},
    publisher = {Clarendon Press},
    keywords = {physics}
}

@online{knuthwebsite,
    author = "Donald Knuth",
    title = "Knuth: Computers and Typesetting",
    url  = "http://www-cs-faculty.stanford.edu/~uno/abcde.html",
    addendum = "(accessed: 01.09.2016)",
    keywords = "latex,knuth"
}

@inbook{knuth-fa,
    author = "Donald E. Knuth",
    title = "Fundamental Algorithms",
    publisher = "Addison-Wesley",
    year = "1973",
    chapter = "1.2",
    keywords  = "knuth,programming"
}
...

在overleaf中打开查看效果

该文件包含了特殊格式的记录;例如,第一个文献引用由以下格式定义:

  • @article{...},这是记录条目的第一行,@article 告诉 BibTeX 这里存储的信息是关于一篇文章的。关于此条目的信息被包含在大括号内。除了示例中显示的条目类型(article、book、online 和 inbook)之外,还有很多其他类型,详见参考指南
  • einstein,标签 einstein 被分配给这个条目,它是一个唯一标识符,可以在文档中用来引用这篇文章。
  • author = "Albert Einstein",这是文献条目中的第一个字段,指示了这篇文章的作者是 Albert Einstein。可以使用相同的键值语法添加多个以逗号分隔的字段,例如:title、pages、year、URL 等。有关可能字段的列表,请参阅参考指南

这个文件中的信息可以在 LaTeX 文档中打印和引用,就像前面的部分所示,使用命令 \addbibresource{sample.bib}。并不是所有 .bib 文件中的信息都会显示出来,这取决于文档中设置的参考文献样式。

14.3自定义参考文献

Biblatex 允许通过简单的方式对参考文献部分进行高度定制。已经提到有多种引用样式参考文献样式可供选择,您还可以创建新的样式。另一个定制选项是更改参考文献部分的默认标题。

\documentclass{article}

\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt
]{biblatex}
\addbibresource{sample.bib}

\title{Bibliography management: \texttt{biblatex} package}
\author{Overleaf}
\date{May 2021}

\begin{document}

\maketitle

Using \texttt{biblatex} you can display a bibliography divided into sections, 
depending on citation type. Let's cite! Einstein's journal paper \cite{einstein} 
and Dirac's book \cite{dirac} are physics-related items. Next, \textit{The \LaTeX\ Companion} 
book \cite{latexcompanion}, Donald Knuth's website \cite{knuthwebsite}, 
\textit{The Comprehensive Tex Archive Network} (CTAN) \cite{ctan} are 
\LaTeX-related items; but the others, Donald Knuth's items, 
\cite{knuth-fa,knuth-acp} are dedicated to programming. 

\medskip

\printbibliography[title={Whole bibliography}]

在overleaf中打开查看效果

image-20240219222647947

附加参数title={Whole bibliography}传递给命令\printbibliography是改变标题的参数

参考文献还可以根据不同的过滤器细分为不同的部分,例如:仅打印来自相同作者、相同期刊或类似标题的参考文献。以下是一个示例:

\printbibliography[type=article,title={Articles only}]
\printbibliography[type=book,title={Books only}]

\printbibliography[keyword={physics},title={Physics-related only}]
\printbibliography[keyword={latex},title={\LaTeX-related only}]

这里,参考文献被分成了 4 个部分。下面解释了所使用的命令的语法:

  • \printbibliography[type=article,title={Articles only}]:仅打印类型为 “article” 的条目,并为该部分设置标题 “Articles only”。相同的语法适用于任何其他条目类型。
  • \printbibliography[keyword={physics},title={Physics-related only}]:过滤包含字段中任何位置出现单词 “physics” 的参考文献条目。为该部分设置标题 “Physics-related only”。

image-20240219223048146

15.在LATEX中创建目录

15.1创建目录

在LATEX中通过使用\tableofcontents创建目录。节、子节和章节自动包含在目录中。要手动添加条目,例如未编号的部分,使用命令\addcontentsline,如示例中所示。

\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{August 2022}
\begin{document}
  
\maketitle
  
\tableofcontents

\section{Introduction}
   
This is the first section.
      
Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit.   Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...
       
\section*{Unnumbered Section}
\addcontentsline{toc}{section}{Unnumbered Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\section{Second Section}
       
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...
\end{document}

在overleaf中打开查看效果

在这里插入图片描述

15.2在目录中增加参考文献

要将参考文献打印到目录中,必须向 \printbibliography 添加一个额外的选项。

\printbibliography[
heading=bibintoc,
title={Whole bibliography}
]

\printbibliography[heading=subbibintoc,type=article,title={Articles only}]

在overleaf中打开查看效果

在目录中添加了一个章节和一个子章节:

  • 第一种情况下,添加 heading=bibintoc 将标题添加到目录中,如果可能的话作为一个无编号的章节,否则作为一个无编号的子章节。
  • 第二种情况下,使用 heading=subbibintoc 将标题作为目录中的第二级条目,例如在这个示例中作为嵌套在 “Whole bibliography” 中的子章节。

16.查找和使用LATEX包

LATEX不仅提供了强大的排版功能,而且还通过使用扩展包提供了一个可扩展的框架。

16.1加载包

包是通过\usepackage命令在文档序言中加载的,但由于(许多)LATEX包提供了一组可用于配置其行为的选项,因此\usepackage命令通常看起来像这样:

\usepackage[options]{somepackage}

方括号“[…]”告诉LATEX当它加载某个包时应该应用哪一组选项。在用户请求的选项集中,单个选项或设置通常用逗号分隔。例如,geometry包提供了许多选项来配置LATEX中的页面布局,因此geometry的典型用法可能是这样的:

\usepackage[total={6.5in,8.75in},
top=1.2in, left=0.9in, includefoot]{geometry}

如果一个LATEX包没有提供任何选项,或者用户想要使用一个包的选项的默认值,它将像这样加载:

\usepackage{somepackage}

当你写 \usepackage[...]{somepackage} 时,LaTeX 会寻找一个名为 somepackage.sty的相应文件,这个文件是它需要加载和处理的——以使包命令可用并执行该包提供的任何其他代码。如果 LaTeX 找不到 somepackage.sty,它会终止并显示错误,如下面的 Overleaf 示例所示:

\documentclass[12pt, letterpaper]{article}
\usepackage{somepackage}% a NON-EXISTENT package
\begin{document}
This will fail!
\end{document}

在overleaf中打开查看效果

16.2查找有关包的信息:CTAN

包是通过Comprehensive TeX Archive Network(通常称为CTAN)分发的,该网络拥有来自2881个贡献者的6287个包。CTAN将自己描述为世界各地的一系列提供与TEX有关的资料供下载互联网站点。

【浏览CTAN以查找有用的软件包】

17.下载完成的LATEX文档

在这里插入图片描述

从Overleaf中导出进阶

常用 LATEX 标签汇总

标签作用
\documentclass{article}声明文档的类型,详细说明
\begin{document}\end{document}文档的内容,详细说明
\usepackage{graphicx} 加载外部包,详细说明
\title{My first LaTeX document}文档的题目,详细说明
\author{Hubert Farnsworth}作者名字,详细说明
\thanks{Funded by the Overleaf team.}致谢,详细说明
\date{August 2024}日期,详细说明
\maketitle 将标题、作者和日期信息显示到文档中,详细说明
% Latex单行注释,详细说明
\textbf{greatest}Latex粗体,详细说明
\textit{accident}Latex斜体,详细说明
\underline{science}Latex下划线,详细说明
\emph{argument}在普通文本中,强调的文本会被斜体化,但如果在斜体文本中使用,则行为相反,详细说明
\includegraphics{universe} 导入图片,详细说明
\includegraphics[width=0.75\textwidth]{mesh}将图形的宽度设置为文本宽度的 75% - 文本宽度的值存储在 \textwidth 命令中,详细说明
\graphicspath{{images/}}定义图片的导入位置,详细说明
\begin{figure}[h]......\end{figure}图像环境,详细说明
\caption{A nice plot.}图形的标题,详细说明
\label{fig:mesh1}给图像设置一个标签,以便在文档中引用它,详细说明
\ref{fig:mesh1}所引用图形对应的编号,详细说明
\begin{itemize} \end{itemize}LATEX无序列表,详细说明
\begin{enumerate} \end{enumerate}LATEX有序列表,详细说明
\( ... \), $ ... $ or \begin{math} ... \end{math}LATEX行内数学表达式,详细说明
\[ ... \], \begin{displaymath} ... \end{displaymath} or \begin{equation} ... \end{equation}LATEX块数学表达式,详细说明
\begin{abstract} \end{abstract}LATEX的摘要,详细说明
\newline \\LATEX的换行,详细说明
\part{part}部分
\chapter{chapter}章节
\section{section}
\subsection{subsection}子节
\subsubsection{subsubsection}子小节
\paragraph{paragraph}段落
\subparagraph{subparagraph}子段落
\begin{tabular}{c c c} \end{tabular}创建表,详细说明
\hline,|表格的水平线与垂直线,详细说明
\begin{table}[h!]......\end{table}表格环境,详细说明
\tableofcontentsLATEX创建目录,详细说明
\addcontentsline将未编号的标题添加到目录中,详细说明
\addbibresource{sample.bib}导入参考文献数据文件 sample.bib,详细说明
\cite{einstein}在文档中插入一个引用,详细说明
\printbibliography打印出引用的参考文献列表,详细说明

【说明】本文翻译自overleaf官网Learn LaTeX in 30 minutes

😃😃😃

  • 23
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值