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

更多教程請關注“數據分析處理”

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