30分钟学习LaTeX (4)

基本格式

现在,我们将研究如何编写摘要,以及如何将LATEX文档格式化为不同的章,节和段落。

摘要

在科学文献中,通常的做法是首先简要概述论文的主要主题。 在LATEX中有一个抽象的环境生成摘要。 该抽象环境会将文本以特殊格式放在文档顶部。

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
 

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}
 
Now that we have written our abstract, we can begin writing our first paragraph.
 
This line will start a second Paragraph.
\end{document}

                                 

 

段落和新行

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
 

\begin{abstract}
This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
\end{abstract}
 
Now that we have written our abstract, we can begin writing our first paragraph.
 
This line will start a second Paragraph.
\end{document}

                                       

写文档正文内容时,如果需要开始新段落,则必须按两次“ Enter”键(以插入两个空行)。 注意,LATEX会自动缩进段落。

要在不实际开始新段落的情况下开始新行,请插入一个换行点,可以通过\\(在示例中为双反斜杠)或\ newline命令来完成。

应注意不要使用多个\\或\ newlines来“模拟”段落之间具有较大间距的段落,因为这可能会干扰LATEX的排版算法。 推荐的方法是继续使用双空行来创建没有任何\\的新段落,然后将 \usepackage{parskip} 添加到序言中。

您可以在“段落和换行”文章中找到更多信息。

章节

组织文档的命令因文档类型而异,最简单的组织形式是分段,所有格式均可用。

\documentclass{report}
\usepackage[utf8]{inputenc}

\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}

                                              

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

                                                    

请注意,\part和\chapter仅在report和book文档类中可用。

有关文档结构的更完整讨论,请参见有关节和章的文章。

创建表格

在LATEX中创建一个简单的表

在下面,您可以看到创建表格的最简单的示例

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{tabu}

\begin{document}


\vspace{1cm}

%---------------------------------------------------------------------
%Simplest working example
\begin{center}
\begin{tabular}{ c c c }
  cell1 & cell2 & cell3 \\ 
  cell4 & cell5 & cell6 \\  
  cell7 & cell8 & cell9    
\end{tabular}
\end{center}
%---------------------------------------------------------------------

\vspace{1cm}

%---------------------------------------------------------------------
%Vertical lines as column separators
\begin{center}
\begin{tabular}{ | c | c | c | } 
  \hline
  cell1 & cell2 & cell3 \\ 
  cell4 & cell5 & cell6 \\ 
  cell7 & cell8 & cell9 \\ 
  \hline
\end{tabular}
\end{center}
%---------------------------------------------------------------------

\vspace{1cm}

%---------------------------------------------------------------------
%Horizontal lines as row separators
\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}
%---------------------------------------------------------------------

\vspace{1cm}




%---------------------------------------------------------------------
%Referencing and captioning tables
The table \ref{table:1} is an example of referenced \LaTeX{} elements.

\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:1}
\end{table}
%---------------------------------------------------------------------




\end{document}

 

                                         

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

添加边框

tabular 环境更加灵活,您可以在每列之间放置分隔线。

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

                                                   

您可以使用水平线命令\hline和垂直线参数|添加边框。

  • { |c|c|c| }:这里声明表中将使用由垂直线分隔的三列。 | 符号指定这些列应由垂直线分隔。
  • \hline:这将插入一条水平线。 在这里,我们在表格的顶部和底部包括了水平线。 对\ hline的使用次数没有限制。

在下面您可以看到第二个示例:

\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}

                                         

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

标题,标签和引用

您可以使用与图像几乎相同的方式来为表添加标题和引用表。 唯一的区别是,使用table环境代替了figure环境。

Table \ref{table:data} is an example of referenced \LaTeX{} elements.

\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会自动为您完成此操作。”

添加目录

创建目录很简单,命令\tableofcontents为您完成所有工作:

\documentclass{article}
\usepackage[utf8]{inputenc}
 
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{ }
  
\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...
       
\addcontentsline{toc}{section}{Unnumbered Section}
\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}

                                      

节,小节和章节将自动包含在目录中。 要手动添加条目(例如,当您需要一个未编号的节时),请使用示例中的命令\addcontentsline。

下载完成的文件

您可以通过单击PDF从上方的左侧菜单中下载完成的PDF。 还有一个更快的选项,单击PDF查看器上的“下载PDF”按钮,如下所示:

                                              

overleaf 中的编辑文档和文档预览的截图:

翻译如下文章

原文:

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes

更多教程请关注“数据分析处理”

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章