注意:这篇文章上次更新于1858天前,文章内容可能已经过时。
This article was last updated1858 days ago, the content may be outdated.
送给那些有写论文需求的小伙伴 😉
顺便提一下 MTAP yyds!
For those of you who need to write papers 😉
By the way, MTAP is the GOAT!
在本指南中,我们希望为您初步介绍一下 LaTeX 。
该指南不需要您具有任何 LaTeX 的先验知识,
不过到您完成时,您将会已经编写出您的第一个 LaTeX 文档,并且如果顺利的话,您将能够对 LaTeX 提供的一些基本功能有很好的了解。
In this guide, we hope to give you a first introduction to LaTeX.
The guide doesn’t require any prior knowledge of LaTeX,
but by the time you finish, you will have written your first LaTeX document, and if all goes well, you will have a good understanding of some of the basic features LaTeX has to offer.
什么是 LaTeX ?
LaTeX (发音为 LAY-tek or LAH-tek) 是个用于创建专业外观文档的工具。
它基于“所见即所得”的思想,这意味着您仅需要关注您文档的内容,接下来计算机会帮你搞定格式。
用户们可以输入纯文本并让 LaTeX 来处理剩余部分,而不是像 Microsoft Word 或 LibreOffice Writer 那样在页面上分割文本去控制格式。
译者注:英式英语:/'leɪteks/ | 美式英语:/'letɛks/
What is LaTeX?
LaTeX (pronounced “LAY-tek” or “LAH-tek”) is a tool for creating professional-looking documents.
It is based on the WYSIWYG (what you see is what you get) idea, which means you only need to focus on the content of your document, and the computer will take care of the formatting for you.
Users can type in plain text and let LaTeX handle the rest, rather than splitting text on the page to control formatting like in Microsoft Word or LibreOffice Writer.
Translator’s note: British English: /'leɪteks/ | American English: /'letɛks/
为什么学习 LaTeX ?
LaTeX 在世界范围内用于科学文档,书籍以及许多其他形式的出版。
它不仅可以创建精美的排版文档,而且还允许用户非常快速地处理排版更为复杂的部分,例如输入数学公式、创建目录、引用和创建书目以及在所有章节中保持一致的布局。
由于可用的开源软件包数量众多(稍后会详细介绍),所以 LaTeX 的可能性是无穷的。
这些软件包允许用户使用 LaTeX 做更多的事情,比如添加脚注、绘制图表格、创建表格等。
人们使用 LaTeX 最重要的原因之一是它分离了文档的内容和样式。
这意味着您一旦写好了文档的内容,我们就可以轻松改变它的外观。
同样,您可以创建一种文档的样式,用来标准化许多不同文档的外观。
这使得科学期刊可以为投稿创建模版。这些模版拥有一个预制布局,而仅需要添加内容。
实际上,从简历到幻灯片的所有内容有上百种可用的模版。
Why learn LaTeX?
LaTeX is used worldwide for scientific documents, books and many other forms of publishing.
Not only can it create beautifully typeset documents, it also allows users to handle the more complex parts of typesetting very quickly, such as inputting mathematical formulas, creating tables of contents, referencing and creating bibliographies, and keeping a consistent layout across all sections.
Because of the vast number of open-source packages available (more on this later), the possibilities with LaTeX are endless.
These packages allow users to do more with LaTeX, such as adding footnotes, drawing tables, creating tables, and so on.
One of the most important reasons people use LaTeX is that it separates the content of a document from its style.
This means that once you have written the content of your document, we can easily change its appearance.
Similarly, you can create a document style that standardizes the look of many different documents.
This allows scientific journals to create templates for submissions. These templates have a pre-built layout, and only the content needs to be added.
In fact, there are hundreds of templates available for everything from CVs to slides.
来写你的第一篇 LaTeX 吧
第一步是创建一个新的 LaTeX 项目。
您可以通过创建新的 .tex 文件来在自己的计算机上做这件事,或者您也可以在 Overleaf 中开始一个新项目。
让我们从最简单的工作示例开始吧:
Writing your first piece of LaTeX
The first step is to create a new LaTeX project.
You can do this on your own computer by creating a new .tex file, or you can start a new project in Overleaf.
Let’s start with the simplest working example:
1 | \documentclass{article} |

As you can see, LaTeX has already handled the first bit of formatting for you by indenting the first line of the paragraph.
Let’s take a closer look at what each part of our code does.
代码的第一行声明了文档的类型,叫做类。这个类控制文档的整体外观。
不同类型的文档将会需要不同的类,即简历相比一篇科学论文将需要一个不同的类。
在这种情况下,这个类是 article,一种最简单最常见的 LaTeX 类。
您如果正在处理其他类型的文档,那可能需要不同的类,例如 book 或者 report。
在此之后,您编写封装在 \begin{document} 和 \end{document} 标签里的文档内容。
这就是文档的主体。你可以在这里开始编写,并根据你的需要来修改文本。
你必须编译文档,才能在 PDF 中查看这些更改的结果。
你只需点击 Recompile 便可在 Overleaf 中执行此操作。
(你也可以通过点击 Recompile 按钮旁的小尖头,并设置 Auto Compile 为开,来将项目设置为在编辑文件时自动重新编译。)
如果你使用的是基础文本编辑器,例如 gedit、emacs、vim、sublime、notepad等,你将不得不手动编译文档。
为此,只需在你的计算机终端/命令行中运行 pdflatex <你的文档>。
有关如何执行此操作的更多信息,请参见此处。
如果你正在使用专用的 LaTeX 编辑器比如 TeXmaker 或者 TeXworks,只需点击 Recompile 按钮。
如果你不确定位置在哪里,请查阅程序文档。
现在您已经了解了如何向文档中添加内容,那么下一步就是给它起个标题。 为此,我们必须简短地谈一下 preamble (preamble 有引言、序文之意,但是这里主要指 LaTeX 中的代码部分,所以保留原词)。
The first line of code declares the type of document, called the class. This class controls the overall appearance of the document.
Different types of documents will require different classes, i.e. a CV will require a different class than a scientific paper.
In this case, the class is article, one of the simplest and most common LaTeX classes.
If you are working on other types of documents, you may need different classes, such as book or report.
After this, you write the content of your document, enclosed within the \begin{document} and \end{document} tags.
This is the body of the document. You can start writing here and modify the text according to your needs.
You must compile the document to see the results of these changes in a PDF.
To do this in Overleaf, you simply click Recompile.
(You can also click the small arrow next to the Recompile button and turn on Auto Compile to have the project recompile automatically as you edit the file.)
If you are using a basic text editor such as gedit, emacs, vim, sublime, notepad, etc., you will have to compile the document manually.
To do this, simply run pdflatex <your document> in your computer’s terminal/command line.
For more information on how to do this, see here.
If you are using a dedicated LaTeX editor such as TeXmaker or TeXworks, just click the Recompile button.
If you are not sure where it is, please consult the program documentation.
Now that you know how to add content to your document, the next step is to give it a title. To do this, we must briefly talk about the preamble.
一篇文档的序文
在上一个示例中,文本是被输入在 \begin {document} 命令之后的。
在此之前,.tex 文件中的的所有内容都被称为 preamble。
在 preamble 中,你定义要编写的文档的类型,编写所用的语言,想要使用的包(稍后会详细介绍)和其他几个元素。
例如,普通文档的 preamble 将如下所示:
The preamble of a document
In the previous example, the text was entered after the \begin {document} command.
Everything in the .tex file before this point is called the preamble.
In the preamble, you define the type of document you are writing, the language you are writing in, the packages you would like to use (more on this later) and several other elements.
For example, the preamble of a normal document would look like this:
1 | \documentclass[12pt, letterpaper]{article} |
下面是每行的详细说明:
Here is a detailed description of each line:
1 | \documentclass[12pt, letterpaper]{article} |
如前所述,这定义了文档的类型。一些包含在方括号里的附加参数可以被传递给命令。
这些参数必须用逗号分隔。在示例中,额外的参数设置字体大小(12pt)和纸张尺寸(letterpaper)。
当然,可以使用其他字体大小(9pt,11pt,12pt),但是如果没有指定,则默认大小为 10pt。
至于纸张尺寸,其他可能的值是 a4paper 和 legalpaper;
请参阅有关页面大小和边距的文章,以获取有关此内容的更多详细信息。
As mentioned before, this defines the type of document. Additional parameters, included in square brackets, can be passed to the command.
These parameters must be separated by commas. In the example, the extra parameters set the font size (12pt) and the paper size (letterpaper).
Of course, other font sizes can be used (9pt, 11pt, 12pt), but if none is specified, the default size is 10pt.
As for the paper size, other possible values are a4paper and legalpaper;
refer to the article on page size and margins for more details on this.
1 | \usepackage[utf8]{inputenc} |
这是文档的编码。它可以被省略或更改为其他编码,但建议使用 utf-8。
除非您特别需要其他编码,否则如果你还不确定的话,请将此行添加到 preamble 中。
This is the encoding of the document. It can be omitted or changed to another encoding, but utf-8 is recommended.
Unless you specifically need another encoding, add this line to your preamble if you are not sure yet.
Adding a title, author and date
To add a title, author and date to your document, you must add three lines to the preamble (not the body of the document).
These lines are
1 | \title{First document} |
这是文档的标题。
This is the title of the document.
1 | \author{Hubert Farnsworth} |
在此处输入作者的姓名,并且作为一个可选项,你可以添加接下来的命令:
Enter the author’s name here, and as an optional extra, you can add the following command:
1 | \thanks{funded by the Overleaf team} |
这可以被添加在标题命令的大括号里作者的姓名之后。它将会添加上标和有着括号内文本的脚注。
如果您需要在文章中感谢一个机构,该功能将非常有用。
This can be added after the author’s name, within the braces of the title command. It will add a superscript and a footnote with the text in brackets.
This feature is very useful if you need to thank an institution in your article.
1 | \date{February 2014} |
您可以手动输入日期或使用命令 \today,以便在编译文档时自动更新日期。
You can type in the date manually or use the command \today to have the date updated automatically when the document is compiled.
添加这些行后,您的 preamble 应该看起来像这样
After adding these lines, your preamble should look like this
1 | \documentclass[12pt, letterpaper, twoside]{article} |
现在,您已经为文档指定了标题,作者和日期,您可以使用 \maketitle 命令在文档上打印此信息。这应被包含在文档的 body(主体,原文加粗,作为 LaTeX 术语) 中您想要打印标题的位置。
Now that you have specified the title, author and date for the document, you can print this information on the document using the \maketitle command. This should be included in the body of the document where you want the title printed.
1 | \begin{document} |
添加注释
与任何你正在编写的任何代码一样,包含注释通常会很有用。注释是您可以包含在文档中的几段文字,这些文字不会被打印,也不会以任何方式影响文档。在调试时,它们对于组织工作,做笔记或注释行/节很有用。要在 LaTeX 中进行注释,只需在行首写一个 % 符号,如下所示:
Adding comments
As with any code you are writing, it is often useful to include comments. Comments are pieces of text you can include in your document that will not be printed and do not affect the document in any way. When debugging, they are useful for organizing your work, taking notes, or commenting out lines/sections. To make a comment in LaTeX, simply write a % symbol at the beginning of the line, as shown below:
1 | \begin{document} |
粗体,斜体和下划线
现在,我们来看一些简单的文本格式命令。
- 粗体:LaTeX 中的粗体文本使用
\textbf{...}命令编写。 - 斜体:LaTeX 中的斜体文本使用
\textit{...}命令编写。 - 下划线:LaTeX 中带下划线的文本使用
\underline{...}命令编写。
下面展示了其中每个实例的示例:
Bold, italics and underlining
Now, let’s look at some simple text formatting commands.
- Bold: bold text in LaTeX is written with the
\textbf{...}command. - Italics: italic text in LaTeX is written with the
\textit{...}command. - Underline: underlined text in LaTeX is written with the
\underline{...}command.
Below is an example showing each of these instances:
1 | Some of the \textbf{greatest} |

另一个非常有用的命令是 \emph{...} 命令。实际上,\emph 命令使用其参数的操作取决于上下文 - 在普通文本中,强调的文本是斜体,但是如果在斜体文本中使用,则此行为是相反的 - 请参见以下示例:

Another very useful command is \emph{...}. Actually, the behavior of the \emph command with its argument depends on the context - in normal text, the emphasized text is italic, but if used in italic text, the behavior is reversed - see the following example:
1 | Some of the greatest \emph{discoveries} |

In addition, some packages, such as Beamer, change the way the \emph command behaves.
添加图像
现在,我们将研究如何将图像添加到 LaTeX 文档中。在 Overleaf 上,您首先必须上传图像。
以下是一个如何包含图片的示例。
译者注:前文使用的是 image ,这里使用的是 picture ,所以分别译为图像、图片。
Adding images
Now, we will look at how to add images to a LaTeX document. On Overleaf, you first have to upload the image.
Below is an example of how to include an image.
Translator’s note: the text above uses “image”, while here it uses “picture”, so they are translated as 图像 (image) and 图片 (picture) respectively.
1 | \documentclass{article} |
LaTeX 不能单独管理图像,因此您需要使用一个包。包可用于更改 LaTeX 文档的默认外观,或允许更多功能。
这种情况下,您需要在我们的文档中包含一个图像,因此您应该使用 graphicx 包。
该软件包提供了新命令 \includegraphics{...} 和 \graphicspath{...}。
要使用 graphicx 包,请在你的 preamble 中包含以下行:\usepackage{graphicx}。
命令 `\graphicspath{ {images/} }告诉 LaTeX,图像被保存在当前目录下名为 images 的文件夹中。
\includegraphics{universe} 是将图像实际包含在文档中的命令。
这里的 universe(宇宙)是包含图像的文件不带扩展名时的名称,所以 universe.png 就变成了 universe。
图像的文件名不应包含空格或多个点。
LaTeX cannot manage images on its own, so you need to use a package. Packages can be used to change the default appearance of a LaTeX document or to allow more functionality.
In this case, you need to include an image in your document, so you should use the graphicx package.
This package provides the new commands \includegraphics{...} and \graphicspath{...}.
To use the graphicx package, include the following line in your preamble: \usepackage{graphicx}.
The command \graphicspath{ {images/} } tells LaTeX that the images are saved in a folder named images in the current directory.
\includegraphics{universe} is the command that actually includes the image in the document.
Here universe is the name of the file containing the image without its extension, so universe.png becomes universe.
The file name of the image should not contain spaces or multiple dots.
注意:文件扩展名是被允许包括进来的,但是最好忽略它。如果省略文件扩展名,它将提示 LaTeX 搜索所有支持的格式。在上传图像文件时,通常也建议使用小写字母作为文件扩展名。有关更多详细信息,请参见生成高分辨率和低分辨率图像的部分。
译者注:该段落原文给出的链接无法跳转到相应的信息部分。
Note: the file extension is allowed to be included, but it is better to omit it. If the file extension is omitted, it prompts LaTeX to search for all supported formats. When uploading image files, it is also usually recommended to use lowercase letters for the file extension. For more details, see the section Generating high-res and low-res images.
Translator’s note: the link given in the original paragraph cannot jump to the corresponding information section.
Captions, labels and references
Images can be captioned, labelled and referenced by means of the figure environment, as shown below:
1 | \begin{figure}[h] |
该示例中包含三个重要的命令:
\caption{a nice plot}:您可能会期望此命令为图形设置标题。如果你创建了一个图形列表,那么标题将会被用在这里。您可以将其放在图的上方或下方。\label{fig:mesh1}:如果您需要在文档中引用图像,请使用此命令设置标签。标签将为图像编号,并与下一个命令结合使用,以供您参考。\ref{fig:mesh1}:该代码将替换为与参考图相对应的数字。
将图像放置在 LaTeX 文档中时,我们应始终将它们放置在图形环境或类似环境中,以便 LaTeX 可以用适合您剩余文本的方式放置图像。
注意:如果您在自己的计算机上使用标题和参考,那你将必须编译两次文档才能使参考正常工作。Overleaf 会自动为您完成此操作。
There are three important commands in this example:
\caption{a nice plot}: as you might expect, this command sets the caption for the figure. If you create a list of figures, the caption will be used there. You can place it above or below the figure.\label{fig:mesh1}: if you need to reference the image within your document, use this command to set a label. The label will number the image, and combined with the next command, it can be used for your reference.\ref{fig:mesh1}: this code will be replaced by the number corresponding to the referenced figure.
When placing images in a LaTeX document, we should always place them in a figure environment or similar environment, so that LaTeX can position the images in a way that suits the rest of your text.
Note: if you use captions and references on your own computer, you will have to compile the document twice for the references to work properly. Overleaf does this automatically for you.
在 LaTeX 中创建列表
在 LaTeX 中创建列表非常简单。您可以使用不同的列表环境创建列表。
环境是我们文档中您希望以与文档其余部分不同方式进行呈现的部分。
它们以 \begin{...} 命令开始,以 \end{...} 命令结束。
列表主要有两种不同的类型,有序列表和无序列表。各自将使用不同的环境。
无序列表
无序列表是由 itemize(逐项列记之意,原文为专有名词)环境生成的。每个条目之前必须带有控制序列 \item,如下所示。
Creating lists in LaTeX
Creating lists in LaTeX is very simple. You can create lists with different list environments.
Environments are sections of your document that you want to be rendered differently from the rest of the document.
They begin with a \begin{...} command and end with an \end{...} command.
There are two main types of lists: ordered lists and unordered lists. Each uses a different environment.
Unordered lists
Unordered lists are produced by the itemize environment. Each entry must be preceded by the control sequence \item, as shown below.
1 | \begin{itemize} |

By default, the individual entries are indicated with a black dot, a so-called bullet. The text in the entries can be of any length.
Ordered lists
Ordered lists have the same syntax rules in different environments. We use the enumerate environment to make ordered lists:
1 | \begin{enumerate} |

As with unordered lists, each entry must be preceded by the control sequence \item, which will automatically generate the number marking that entry. Enumerated labels consist of sequential numbers starting from 1.
为 LaTeX 添加数学符号
LaTeX 的主要优点之一是易于编写数学表达式。
LaTeX 允许两种用于数学表达式的书写模式:inline(内联)模式和 display(显示)模式。
第一种方式用于编写作为文本一部分的公式。第二种方式用于编写不属于文本或段落的表达式,因此被放在单独的行上。
让我们看一个 inline 模式的例子:
Adding math to LaTeX
One of the main advantages of LaTeX is the ease of writing mathematical expressions.
LaTeX allows two writing modes for mathematical expressions: the inline mode and the display mode.
The first is used to write formulas that are part of the text. The second is used to write expressions that do not belong to the text or paragraph, and are therefore placed on a separate line.
Let’s look at an example of the inline mode:
1 | In physics, the mass-energy equivalence is stated |

要使用 inline 模式来放置方程式,请使用以下定界符之一:\( ... \),$ ... $ 或 \begin{math} ... \end{math}。它们都能够起作用,选择那种取决于个人口味。
displayed 模式有两种版本:已编号和未编号。

To place an equation in inline mode, use one of these delimiters: \( ... \), $ ... $ or \begin{math} ... \end{math}. They all work; which one you choose depends on personal taste.
The displayed mode has two versions: numbered and unnumbered.
1 | The mass-energy equivalence is described by the famous equation |

要在 display 模式下打印方程式,请使用以下定界符之一:\[ ... \],\begin{displaymath} ... \end{displaymath} 或 \begin{equation} ... \end{equation}。
不鼓励使用 $$ ... $$,因为它会产生不一致的间距,并且和某些数学程序包一起使用时可能表现得不是很好。
重要说明:equation* 环境是由外部软件包提供的,请参阅 amsmath 的文章。
许多数学模式命令都需要 amsmath 程序包,因此在编写数学公式时请确保将其包括在内。
下面显示了一些基本数学模式命令的示例。

To print an equation in display mode, use one of these delimiters: \[ ... \], \begin{displaymath} ... \end{displaymath} or \begin{equation} ... \end{equation}.
Using $$ ... $$ is discouraged, as it produces inconsistent spacing and may not behave well with some math packages.
Important note: the equation* environment is provided by an external package, please refer to the amsmath article.
Many commands for math mode require the amsmath package, so make sure to include it when writing math formulas.
Below are some examples of basic math mode commands.
1 | Subscripts in math mode are written as $a_b$ and superscripts are written as $a^b$. These can be combined an nested to write expressions such as |

The possibilities of math in LaTeX are endless; it is impossible to list them all here.
Be sure to check out our other articles here
- 数学表达式 - Mathematical expressions
- 下标和上标 - Subscripts and superscripts
- 方括号和圆括号 - Brackets and Parentheses
- 分数和二项式 - Fractions and Binomials
- 对齐等式 - Aligning Equations
- 运算符 - Operators
- 数学模式下的间距 - Spacing in math mode
- 积分,总和与极限 - Integrals, sums and limits
- 在数学模式下显示样式 - Display style in math mode
- 希腊字母和数学符号列表 - List of Greek letters and math symbols
- 数学字体 - Mathematical fonts
基本格式
现在,我们将研究如何编写摘要,以及如何将 LaTeX 文档格式化为不同的章、节和段落。
摘要
在科学文献中,通常的做法是简要概述论文的主题。
在 LaTeX 中有一个 abstract(摘要)的环境。abstract 环境会将文本以特殊格式放在你文档的顶部。
Basic formatting
Now, we’ll look at how to write an abstract and how to format a LaTeX document into different chapters, sections and paragraphs.
Abstract
In scientific literature, it is common practice to give a brief overview of the subject of the paper.
In LaTeX there is an abstract environment. The abstract environment places the text at the top of your document in a special format.
1 | \begin{document} |
1 | \begin{document} |

在编写文档内容时,如果需要开始新的段落,你必须按两次 “Enter” 键(以插入双空行)。
注意,LaTeX 会自动缩进段落。
想要开始新行而不实际开始新段落,请插入一个换行点,这可以通过 \(在示例中为双反斜杠)或 \newline 命令来实现。
注意不要使用多个 \ 或 \newlines 来“模拟”段落之间具有较大间距的段落,因为这可能会干扰 LaTeX 的排版算法。
推荐的方法是继续使用双空行创建没有任何 \ 的新段落,然后将 \usepackage{parskip} 添加到序言中。
您可以在 段落和换行 文章中找到更多信息。

When writing the content of your document, if you need to start a new paragraph, you must press “Enter” twice (to insert a double blank line).
Note that LaTeX automatically indents paragraphs.
If you want to start a new line without actually starting a new paragraph, insert a line break point, which can be done with \ (double backslash in the example) or the \newline command.
Be careful not to use multiple \ or \newlines to “simulate” paragraphs with large spacing between them, as this may interfere with LaTeX’s typesetting algorithm.
The recommended approach is to continue using double blank lines to create new paragraphs without any \, and then add \usepackage{parskip} to the preamble.
You can find more information in the Paragraphs and new lines article.
Sections
The commands for organizing a document differ by document type; the simplest form of organization is segmentation, which is available in all formats.
1 | \chapter{First Chapter} |

命令 \section{} 标记新节的开始,在大括号内设置标题。
段编号是自动生成的,可以通过在段命令中包含 * 作为 \section*{}来禁用。 我们也可以有多个\subsection{},也可以有多个\subsubsection{}。下面列出了基本的深度级别:

The command \section{} marks the beginning of a new section, with the title set inside the braces.
Section numbering is generated automatically, and can be disabled by including * in the section command, e.g. \section*{}. We can also have multiple \subsection{} and multiple \subsubsection{}. The basic depth levels are listed below:
| -1 | \part{part} |
|---|---|
| 0 | \chapter{chapter} |
| 1 | \section{section} |
| 2 | \subsection{subsection} |
| 3 | \subsubsection{subsubsection} |
| 4 | \paragraph{paragraph} |
| 5 | \subparagraph{subparagraph} |
请注意,\part 和 \chapter 仅在 report(报告)和 book(书籍)文档类中可用。
有关文档结构的更完整讨论,请参见有关节和章的文章。
Note that \part and \chapter are only available in the report and book document classes.
For a more complete discussion of document structure, see the article on sections and chapters.
Creating tables
Creating a simple table in LaTeX
Below you can see a minimal working example of a table
1 | \begin{center} |

tabular(表格)环境是 LaTeX 创建表格的默认方法。您必须为此环境指定一个参数,在这种情况下为 {c c c}。
这告诉 LaTeX 这里将有三列,并且每列中的文本必须居中。您也可以使用 r 将文本向右对齐,使用 l 进行左对齐。
对齐符号 & 用于指定表格条目中的分隔符。每行中的对齐符号必须始终少于列数。
要转到表格的下一行,我们使用换行命令 \\。我们将整个表格包装在 center(中心)环境中,以便它出现在页面的中心。

The tabular environment is the default way LaTeX creates tables. You must specify a parameter for this environment; in this case it is {c c c}.
This tells LaTeX that there will be three columns and that the text in each column must be centered. You can also use r to right-align the text and l to left-align it.
The alignment symbol & is used to specify the separators within table entries. Each row must always contain fewer alignment symbols than the number of columns.
To move to the next row of the table, we use the line break command \\. We wrap the entire table in a center environment so that it appears in the center of the page.
Adding borders
The tabular environment is more flexible; you can place separator lines between each column.
1 | \begin{center} |

您可以使用水平线命令 \hline 和垂直线参数 | 添加边框。
{ |c|c|c| }:这声明了被垂直线分割的三列,并将被应用在表格中。|符号指定这些列应由一条垂直线分隔。\hline:这将插入一条水平线。在这里,我们在表格的顶部和底部包括了水平线。你使用\hline的次数没有限制。
在下面您可以看到第二个示例。

You can add borders using the horizontal line command \hline and the vertical line parameter |.
{ |c|c|c| }: this declares three columns separated by vertical lines, which will be applied in the table. The|symbol specifies that these columns should be separated by a vertical line.\hline: this inserts a horizontal line. Here, we have included horizontal lines at the top and bottom of the table. There is no limit to how many times you can use\hline.
Below you can see a second example.
1 | \begin{center} |

有时在 LaTeX 中创建表格可能会有些棘手,因此您可能想使用 TablesGenerator.com 在线工具导出表格的 [LaTeX] 代码。File > Paste table data(文件 > 粘贴表格数据)选项使您可以从电子表格应用程序复制和粘贴数据。

Creating tables in LaTeX can sometimes be a bit tricky, so you may want to use the online tool TablesGenerator.com to export the [LaTeX] code for your table. The File > Paste table data option allows you to copy and paste data from a spreadsheet application.
Captions, labels and references for tables
You can add captions and references to tables in much the same way as with images. The only difference is that the table environment is used instead of the figure environment.
1 | Table \ref{table:data} is an example of referenced \LaTeX{} elements. |

Note: if you use captions and references on your own computer, you must compile the document twice for the references to work properly. Overleaf does this automatically for you.
Adding a table of contents
Creating a table of contents is simple; the command \tableofcontents does all the work for you:
1 | \documentclass{article} |

Sections, subsections and chapters will be automatically included in the table of contents. To add entries manually (for example, when you want an unnumbered section), use the command \addcontentsline as in the example.
Downloading your finished file
You can download your finished PDF by clicking on the PDF icon in the left-hand menu at the top.
A faster option is to click the Download PDF button in the PDF viewer, as shown below.

Repost notice
Original author: 云游君
Original link: https://www.yunyoujun.cn/share/trans-learn-latex-in-30-minutes






