> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md).

# 建立你的第一份 LaTeX 文件

**新功能：造訪新的** [**Overleaf 學習中心**](https://learn.overleaf.com/) **來探索免費線上課程和即時網路研討會——你掌握 LaTeX 並充分發揮 Overleaf 功能所需的一切。**

這個入門教學不假設你有任何 LaTeX 經驗，但希望在完成時，你不僅已寫出第一份 LaTeX 文件，還能獲得足夠的知識與信心，朝著精通 LaTeX 邁出下一步。

## 什麼是 LaTeX？

LaTeX（發音為「*LAY*-tek」或「*LAH*-tek」）是一種用於排版專業外觀文件的工具。然而，LaTeX 的運作方式與你可能用過的許多其他文件製作應用程式大不相同，例如 Microsoft Word 或 LibreOffice Writer：那些「[所見即所得](https://en.wikipedia.org/wiki/WYSIWYG)」工具會提供使用者一個互動式頁面，讓他們在其中輸入、編輯文字並套用各種格式樣式。LaTeX 的運作方式則大不相同：你的文件其實是一個純文字檔，內插著 LaTeX *命令* 指令，用來表達所需的（排版後）結果。要產生一份可見且排版完成的文件，你的 LaTeX 檔案會經由一套名為 *TeX 引擎* 的軟體處理，這套軟體會使用你文字檔中內嵌的指令來引導並控制排版程序，將 LaTeX 指令和文件文字轉換為專業排版的 PDF 檔案。這表示你只需要專注於文件的 *內容* 內容，而電腦會透過 LaTeX 指令和 TeX 引擎來處理 *視覺外觀* （格式）。

## 為什麼要學習 LaTeX？

可以提出許多支持或反對學習使用 LaTeX 取代其他文件編寫應用程式的論點；但最終這仍是基於偏好、習慣以及文件需求的個人選擇。

支持 LaTeX 的論點包括：

* 支援為物理科學領域中極為複雜的數學、表格和技術內容進行排版；
* 提供腳註、交叉參照與參考文獻管理功能；
* 可輕鬆產生複雜或繁瑣的文件元素，例如索引、術語表、目錄、圖表清單；
* 由於其內建的可程式化能力，以及透過數千個 [免費附加套件](https://www.ctan.org/pkg).

整體而言，LaTeX 讓使用者能夠對文件製作擁有相當程度的控制，並將文件排版到極高標準。當然，也有一些文件或出版品類型並不適合 LaTeX，包括許多雜誌類出版物中常見的「自由形式」版面設計。

LaTeX 的一項重要優點，是將文件內容與文件樣式分離：一旦你寫好文件內容，就可以很輕鬆地更改其外觀。同樣地，你可以建立一個定義特定文件類型版面／樣式的 LaTeX 檔案，而該檔案可作為 *範本* ，用來標準化該類型額外文件的撰寫／製作；例如，這讓科學出版商能在 LaTeX 中建立文章範本，供作者撰寫投稿期刊的論文。Overleaf 有一個 [包含數千個範本的圖庫](https://www.overleaf.com/gallery)，涵蓋範圍極其廣泛——從科學論文、報告和書籍到履歷和簡報，一應俱全。由於這些範本定義了文件的版面與樣式，作者只需在 Overleaf 中開啟它們——建立新專案——然後開始撰寫內容即可。

## 撰寫你的第一段 LaTeX

第一步是建立一個新的 LaTeX 專案。你可以在自己的電腦上建立一個新的 `.tex` 檔案；或者，你也可以 [在 Overleaf 中開始新專案](/latex/zh-tw/zhi-shi-ku/031-creating-a-document-in-overleaf.md).

讓我們從最簡單的可運作範例開始，它可直接在 Overleaf 中開啟：

```latex
\documentclass{article}
\begin{document}
第一份文件。這是一個簡單的範例，沒有包含任何
額外參數或套件。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Simplest+working+example+LaTeX+document\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AFirst+document.+This+is+a+simple+example%2C+with+no+%0Aextra+parameters+or+packages+included.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![範例文件](/files/522d265ebb96d6ffaa26ab36093c908af5fb5735)

你可以看到 LaTeX 已自動縮排段落的第一行，替你處理了那部分格式。讓我們仔細看看程式碼每個部分的作用。

程式碼的第一行， `\documentclass{article}`，宣告了文件類型，也就是其 *類別*類別 `article` 類別。不同類型的文件需要不同的類別；例如，履歷／CV 需要不同於科學論文的類別，而科學論文可能會使用標準的 LaTeX `book` 或 `報告`。若想更了解可用的眾多 LaTeX 類別類型， [請造訪 CTAN（Comprehensive TeX Archive Network，綜合 TeX 檔案網路）上的相關頁面](https://www.ctan.org/topic/class).

在設定好文件類別後，我們的內容，也就是文件的 *主體* ，會寫在 `\begin{document}` 和 `\end{document}` 標記之間。開啟上方範例後，你可以修改文字，完成後再透過 *重新編譯文件*來檢視產生的排版 PDF。若要在 Overleaf 中這麼做，只需按下 **重新編譯**，如這段簡短影片所示：

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/6yo2PA5aMV3OEZl5NtZKWu/54395f569b830b8183b5e0058d5bc0cc/LL30recompile.mp4>" %}

任何 Overleaf 專案都可以設定為每次編輯時自動重新編譯：點擊 **重新編譯** 按鈕旁的小箭頭，並設定 **自動編譯** 改為 **開啟**，如下圖所示：

![顯示如何將 Auto Compile 設為開啟或關閉的螢幕截圖](/files/4c7fb65a1e8dcd0d7e00a5af6928ed246b37786e)

既然已經看過如何為文件加入內容，下一步就是為它加入標題。為此，我們必須先簡要談談 **前言區**.

## 文件的導言區

上方螢幕截圖顯示 Overleaf 將一份 LaTeX 文件儲存為名為 `main.tex`的一個重要重點： `.tex` 副檔名依慣例用於為包含文件 LaTeX 程式碼的檔案命名。

前一個範例顯示文件內容是如何在 `\begin{document}` 命令之後輸入；然而，你的 `.tex` 檔案中出現在 *，在* 該點之前的所有內容都稱為 *前言區*，它扮演文件的「設定」區段角色。在導言區中，你會定義文件類別（類型），以及撰寫文件時要使用的語言等細節；載入你想要使用的 *套件* （稍後會再詳述 [），以及在此套用其他類型的設定。](#finding-and-using-latex-packages)稍後

最簡單的文件導言區可能如下所示：

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

其中 `\documentclass[12pt, letterpaper]{article}` 定義文件的整體類別（類型）。其他參數必須以逗號分隔，並寫在方括號（`[...]`）中，用來設定這個 article 類別的此一實例；也就是我們希望用於此特定 `article`-類型文件的設定。

在這個範例中，兩個參數的作用如下：

* `12pt` 設定字型大小
* `letterpaper` 設定紙張大小

當然，也可以使用其他字型大小， `9pt`, `11pt`, `12pt`，但如果未指定，預設大小為 `10pt`。至於紙張大小，其他可能值包括 `a4paper` 和 `legalpaper`。更多資訊請參閱關於 [頁面大小與邊距](/latex/zh-tw/ge-shi-hua/07-page-size-and-margins.md).

導言區中的這一行

```latex
\usepackage{graphicx}
```

是載入外部套件的範例（此處為 [`graphicx`](https://ctan.org/pkg/graphicx?lang=en)），用來擴充 LaTeX 的功能，使其能匯入外部圖形檔案。LaTeX 套件會在章節 [尋找與使用 LaTeX 套件](#finding-and-using-latex-packages).

## 加入標題、作者與日期資訊

要為文件加入標題、作者和日期，需要在 *前言區* (*不* （文件主體）中再加入三行。這三行如下：

* `\title{我的第一份 LaTeX 文件}`：文件標題
* `\author{Hubert Farnsworth}`：在這裡填入作者姓名，並可選擇填入 `\thanks` 命令，放在大括號內：
  * `\thanks{由 Overleaf 團隊資助。}`：可在作者姓名之後、 `author` 命令的大括號內加入。這會新增上標與腳註，腳註文字就是大括號內的內容。若你需要在文章中感謝某個機構，這會很有用。
* `\date{2022 年 8 月}`：你可以手動輸入日期，或使用 `\today` 命令，每次文件編譯時都排版當前日期

加入這些行之後，你的導言區應該會像這樣：

```latex
\documentclass[12pt, letterpaper]{article}
\title{我的第一份 LaTeX 文件}
\author{Hubert Farnsworth\thanks{由 Overleaf 團隊資助。}}
\date{2022 年 8 月}
```

要排版標題、作者和日期，請在文件的 `\maketitle` 命令 *主體* 中使用

```latex
\begin{document}
\maketitle
現在我們已為第一份 \LaTeX{} 文件加入標題、作者和日期了！
\end{document}
```

現在可以將導言區和主體合併，產生一份可在 Overleaf 中開啟的完整文件：

```latex
\documentclass[12pt, letterpaper]{article}
\title{我的第一份 LaTeX 文件}
\author{Hubert Farnsworth\thanks{由 Overleaf 團隊資助。}}
\date{2022 年 8 月}
\begin{document}
\maketitle
現在我們已為第一份 \LaTeX{} 文件加入標題、作者和日期了！
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=My+first+LaTeX+document\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Ctitle%7BMy+first+LaTeX+document%7D%0A%5Cauthor%7BHubert+Farnsworth%5Cthanks%7BFunded+by+the+Overleaf+team.%7D%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0AWe+have+now+added+a+title%2C+author+and+date+to+our+first+%5CLaTeX%7B%7D+document%21%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![用 LaTeX 產生的簡單文件圖像](/files/0cbc7f6b61dd0b47da3c3e54639472e454299de7)

## 加入註解

LaTeX 是一種「程式碼」，但專門用於文件排版；因此，與任何其他程式語言撰寫的程式碼一樣，在文件中加入註解會非常有用。LaTeX 註解是一段不會被排版、也不會以任何方式影響文件的文字——常用於加入「待辦」備註；補充說明；為棘手的巨集提供內嵌解釋，或在除錯時將 LaTeX 程式碼的某些行／區塊註解掉。

要在 LaTeX 中加入註解，只需在行首寫一個 `%` 符號，如下方使用上方範例的程式碼所示：

```latex
\documentclass[12pt, letterpaper]{article}
\title{我的第一份 LaTeX 文件}
\author{Hubert Farnsworth\thanks{由 Overleaf 團隊資助。}}
\date{2022 年 8 月}
\begin{document}
\maketitle
現在我們已為第一份 \LaTeX{} 文件加入標題、作者和日期了！

% 這一行是註解。它不會被排版到文件中。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=My+first+LaTeX+document+with+a+comment\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Ctitle%7BMy+first+LaTeX+document%7D%0A%5Cauthor%7BHubert+Farnsworth%5Cthanks%7BFunded+by+the+Overleaf+team.%7D%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0AWe+have+now+added+a+title%2C+author+and+date+to+our+first+%5CLaTeX%7B%7D+document%21%0A%0A%25+This+line+here+is+a+comment.+It+will+not+be+typeset+in+the+document.%0A%5Cend%7Bdocument%7D)

這個範例產生的輸出與前一段不含註解的 LaTeX 程式碼完全相同。

## 粗體、斜體與底線

接下來，我們要看看一些文字格式化命令：

* **粗體**：在 LaTeX 中，粗體文字是使用 `\textbf{...}` 指令。
* *斜體*：斜體文字是使用 `\textit{...}` 指令。
* 底線：要為文字加底線，請使用 `\underline{...}` 指令。

下一個範例示範這些命令：

```latex
其中一些 \textbf{最偉大的}
在 \underline{科學} 中的發現
是因 \textbf{\textit{意外}} 而發現的。
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=First+example+with+formatted+text\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Ctitle%7BMy+first+LaTeX+document%7D%0A%5Cauthor%7BHubert+Farnsworth%5Cthanks%7BFunded+by+the+Overleaf+team.%7D%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0ASome+of+the+%5Ctextbf%7Bgreatest%7D%0Adiscoveries+in+%5Cunderline%7Bscience%7D+%0Awere+made+by+%5Ctextbf%7B%5Ctextit%7Baccident%7D%7D.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 文件中格式化文字的圖片](/files/20aed66cc0f9fb9515ea46929e951b28dbcaa45a)

另一個非常有用的命令是 `\emph{*參數*}`，其對其 `*參數*` 的效果取決於上下文。在一般文字中，強調文字會以斜體顯示，但若用在斜體文字中，則其行為會反轉——請看下一個範例：

```latex
科學中一些最偉大的 \emph{發現}
是因意外而發現的。

\textit{其中一些最偉大的 \emph{發現}
都是偶然發現的。}

\textbf{其中一些最偉大的 \emph{發現}
都是偶然發現的。}
```

[在 Overleaf 中開啟這個 `**\emph**` Overleaf 中的範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+emph+command\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%2C+twoside%5D%7Barticle%7D%0A%5Ctitle%7BMy+first+LaTeX+document%7D%0A%5Cauthor%7BHubert+Farnsworth%5Cthanks%7BFunded+by+the+Overleaf+team.%7D%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cparindent0pt%25+To+remove+the+paragraph+indentation%0A%5Cmaketitle%0ASome+of+the+greatest+%5Cemph%7Bdiscoveries%7D+in+science+%0Awere+made+by+accident.%0A%0A%5Ctextit%7BSome+of+the+greatest+%5Cemph%7Bdiscoveries%7D+%0Ain+science+were+made+by+accident.%7D%0A%0A%5Ctextbf%7BSome+of+the+greatest+%5Cemph%7Bdiscoveries%7D+%0Ain+science+were+made+by+accident.%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![用於示範 LaTeX \emph 命令的圖片](/files/a6523422547ab40ad331fb17bbdb5b005932f08a)

* **注意：** 某些套件，例如 [Beamer](/latex/zh-tw/jian-bao/01-beamer.md)，會改變 `\emph` 指令。

## 加入圖片

在本節中，我們將探討如何將圖片加入 LaTeX 文件。Overleaf 支援三種插入圖片的方法：

1. 請使用 [**插入圖形** 按鈕](https://learn.overleaf.com/learn/Kb/How_to_insert_figures_in_Overleaf#Using_Insert_Figure_to_add_a_figure_to_your_project)(![The Insert Figure button on the editor toolbar](/files/806f9266d789b09f529dbbb2345b82abf69a37a5)），位於編輯器工具列上，用來將圖片插入 **視覺編輯器** 或 **程式碼編輯器**.
2. [複製並貼上圖片](/latex/zh-tw/zhi-shi-ku/075-how-to-paste-formatted-content-into-overleaf.md#pasting-images-into-your-overleaf-project) 匯入 **視覺編輯器** 或 **程式碼編輯器**.
3. 使用 **程式碼編輯器** 來撰寫插入圖形的 LaTeX 程式碼。

選項 1 和 2 會自動產生插入圖片所需的 LaTeX 程式碼，但在這裡我們介紹選項 3——請注意，你需要 [上傳那些圖片](/latex/zh-tw/zhi-shi-ku/088-including-images-on-overleaf.md) 到你的 Overleaf 專案。以下範例示範如何加入圖片：

```latex
\documentclass{article}
\usepackage{graphicx} % 用於匯入圖形的 LaTeX 套件
\graphicspath{{images/}} % 設定 graphicx 套件的圖形路徑

\begin{document}
宇宙浩瀚而且似乎是均勻的，
在大尺度上，無論我們看向何處皆然。

% \includegraphics 命令是
% 由
% graphicx 套件提供（實作）的
\includegraphics{universe}

上方有一張星系圖片。
\end{document}
```

[在 Overleaf 中開啟這個圖片範例。](https://www.overleaf.com/project/new/template/25686?id=107971142\&templateName=Example+using+images+in+LaTeX\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=)

此範例會產生以下輸出：

![示意將圖片匯入 LaTeX 文件的圖示](/files/043154ea93d758d71d65a94f8dad32ce29a78573)

將圖形匯入 LaTeX 文件需要 [附加元件 *套件*](#finding-and-using-latex-packages) ，它提供了加入外部圖形檔案所需的命令與功能。上面的範例載入了 [`graphicx` 套件](https://ctan.org/pkg/graphicx?lang=en) ，其中除了許多其他命令外，還提供了 `\includegraphics{...}` 來匯入圖形，以及 `\graphicspath{...}` 來告訴 LaTeX 圖形位於何處。

若要使用 `graphicx` 套件，請在 Overleaf 文件的導言區中加入以下一行：

```latex
\usepackage{graphicx}
```

在我們的範例中，命令 `\graphicspath{{images/}}` 告訴 LaTeX 圖片存放在名為 `images`的資料夾中，而該資料夾位於目前目錄：

![顯示 LaTeX 存取儲存在資料夾中的圖片的圖示](/files/1dd8c0cac0ba4010ca4fcb037914fa61540d8678)

該 `\includegraphics{universe}` 命令才是將圖片插入文件的實際工作。在這裡， `universe` 是圖片檔名，但不含副檔名。

**注意**:

* 雖然在 `\includegraphics` 命令中可以使用包含副檔名的完整檔名，但最佳做法是省略副檔名，因為這會促使 LaTeX 搜尋所有支援的格式。
* 一般來說，圖形檔名不應包含空白或多個句點；上傳圖片檔案到 Overleaf 時，也建議副檔名使用小寫字母。

更多關於 LaTeX 套件的資訊，可在本教學末尾的 [尋找與使用 LaTeX 套件](#finding-and-using-latex-packages).

## 標題、標籤與參照

圖片可以透過 `figure` 環境加入圖說、標籤並加以參照，如下所示：

```latex
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{images/}}

\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.75\textwidth]{mesh}
    \caption{一張不錯的圖表。}
    \label{fig:mesh1}
\end{figure}

如你在圖 \ref{fig:mesh1} 中所見，函數在原點附近遞增。這個範例位於第 \pageref{fig:mesh1} 頁。

\end{document}
```

[在 Overleaf 中開啟這個圖片範例。](https://www.overleaf.com/project/new/template/25519?id=107980830\&templateName=Example+using+image+captions+in+LaTeX\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=)

此範例會產生以下輸出：

![顯示 LaTeX 中圖說使用方式的圖示](/files/467514477ea21909cb629de57f519f5234601d71)

範例中有幾個值得注意的命令：

* **`\includegraphics[width=0.75\textwidth]{mesh}`**：此形式的 `\includegraphics` 指示 LaTeX 將圖形寬度設為文字寬度的 75%——其值儲存在 `\textwidth` 指令。
* **`\caption{一張不錯的圖表。}`**：顧名思義，這個命令設定圖說，可放在圖形上方或下方。如果你建立圖表清單，這個圖說將會用於該清單中。
* **`\label{fig:mesh1}`**：若要在文件中參照這張圖片，你可以使用 `\label` 命令為它加上標籤。該標籤會用來產生圖片編號，並搭配下一個命令，讓你能引用它。
* **`\ref{fig:mesh1}`**：這段程式碼會被替換為對應於所參照圖形的編號。

納入 LaTeX 文件的圖片應放在 `figure` 環境中或類似結構內，這樣 LaTeX 才能自動將圖片放在文件中的合適位置。

以下 Overleaf 說明文章提供進一步指引：

* [圖形的位置](/latex/zh-tw/tu-biao-yu-biao-ge/02-positioning-images-and-tables.md)
* [插入圖片](/latex/zh-tw/geng-duo-zhu-ti/27-inserting-images.md)

## 在 LaTeX 中建立清單

你可以使用 *環境*建立不同類型的清單，這些環境用來包裝實作特定排版功能所需的 LaTeX 程式碼。一個環境以 `\begin{*環境名稱*}` 開頭，並以 `\end{*環境名稱*}` 其中 `*環境名稱*` 可以是 `figure`, `tabular` 或下列清單類型之一： `itemize` 用於無序清單，或 `enumerate` 用於有序清單。

### 無序清單

無序清單是由 `itemize` 環境產生的。每個清單項目都必須在前面加上 `\item` 命令，如下所示：

```latex
\documentclass{article}
\begin{document}
\begin{itemize}
  \item 個別項目會以黑點，也就是所謂的項目符號標示。
  \item 項目中的文字可以長短不拘。
\end{itemize}
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+a+LaTeX+unordered+list\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bitemize%7D%0A++%5Citem+The+individual+entries+are+indicated+with+a+black+dot%2C+a+so-called+bullet.%0A++%5Citem+The+text+in+the+entries+may+be+of+any+length.%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX 中項目符號清單的範例](/files/124e475e66a16f5efe7835b2287bc702403b36e1)

你也可以開啟這個 [較大型的 Overleaf 專案](https://www.overleaf.com/project/new/template/25521?id=107987258\&templateName=Demonstrating+various+types+of+LaTeX+list\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=) ，其中示範了各種 LaTeX 清單。

### 有序清單

有序清單使用與無序清單相同的語法，但會使用 `enumerate` 環境：

```latex
\documentclass{article}
\begin{document}
\begin{enumerate}
  \item 這是清單中的第一個項目。
  \item 隨著我們加入每個項目，清單編號會遞增。
\end{enumerate}
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+enumerate+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Benumerate%7D%0A++%5Citem+This+is+the+first+entry+in+our+list.%0A++%5Citem+The+list+numbers+increase+with+each+entry+we+add.%0A%5Cend%7Benumerate%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX 產生的編號清單範例](/files/c67c4a9c2c2983361861f25affa416c8759d9a41)

如同 `無序` 清單一樣，每個項目都必須在前面加上 `\item` 命令，這裡會自動產生數字型有序清單標籤值，從 1 開始。

如需更多資訊，你可以開啟這個 [較大型的 Overleaf 專案](https://www.overleaf.com/project/new/template/25521?id=107987258\&templateName=Demonstrating+various+types+of+LaTeX+list\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=) ，其中示範了各種 LaTeX 清單，或造訪我們專門的 [LaTeX 清單說明文章](/latex/zh-tw/latex-ji-chu/04-lists.md)，其中提供更多範例，並說明如何建立自訂清單。

## 在 LaTeX 中加入數學

LaTeX 的主要優點之一，就是數學式子能以非常容易的方式撰寫。LaTeX 提供兩種撰寫模式來排版數學：

* *行內* 用於撰寫段落中公式的數學模式
* *顯示* 用於撰寫不屬於文字或段落、並以獨立行排版的表達式之數學模式

### 行內數學模式

讓我們看一個行內數學模式的範例：

```latex
\documentclass[12pt, letterpaper]{article}
\begin{document}
在物理學中，質能等價性表述為
由方程式 $E=mc^2$ 表示，該式由愛因斯坦於 1905 年提出。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Inline+LaTeX+maths+example\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AIn+physics%2C+the+mass-energy+equivalence+is+stated+%0Aby+the+equation+%24E%3Dmc%5E2%24%2C+discovered+in+1905+by+Albert+Einstein.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示行內數學模式排版的圖片](/files/3ac966919f81ea34e41e0cd45fe23f33a1dcf454)

要排版行內模式數學，你可以使用以下其中一組分隔符號： `\( ... \)`, `$ ... $` 或 `\begin{math} ... \end{math}`，如下列範例所示：

```latex
\documentclass[12pt, letterpaper]{article}
\begin{document}
\begin{math}
E=mc^2
\end{math} 會以行內數學模式排版在段落中——$E=mc^2$ 也是如此，\(E=mc^2\) 亦然。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+inline+math+mode\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bmath%7D%0AE%3Dmc%5E2%0A%5Cend%7Bmath%7D+is+typeset+in+a+paragraph+using+inline+math+mode---as+is+%24E%3Dmc%5E2%24%2C+and+so+too+is+%5C%28E%3Dmc%5E2%5C%29.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![示範使用 LaTeX 行內數學模式產生內容的圖片](/files/5b640368afd851192ac4b0ff30e7a2c48d17279b)

### 顯示數學模式

以顯示模式排版的方程式可以有編號或不編號，如下列範例所示：

```latex
\documentclass[12pt, letterpaper]{article}
\begin{document}
質能等價性由著名方程式描述
\[ E=mc^2 \] 由 Albert Einstein 於 1905 年發現。

在自然單位中（$c = 1$），這個公式表達了恆等式
\begin{equation}
E=m
\end{equation}
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Display+math+mode+example\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AThe+mass-energy+equivalence+is+described+by+the+famous+equation%0A%5C%5B+E%3Dmc%5E2+%5C%5D+discovered+in+1905+by+Albert+Einstein.+%0A%0AIn+natural+units+%28%24c+%3D+1%24%29%2C+the+formula+expresses+the+identity%0A%5Cbegin%7Bequation%7D%0AE%3Dm%0A%5Cend%7Bequation%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 中顯示模式數學的圖片](/files/af547c1bf2d790da830a296aa4efdf10a578412f)

要排版顯示模式數學，你可以使用以下其中一組分隔符號： `\[ ... \]`, `\begin{displaymath} ... \end{displaymath}` 或 `\begin{equation} ... \end{equation}`。歷史上，排版顯示模式數學需要使用 `$$` 字元分隔符號，如 `$$ *... display math here ...*$$`，但這種方法 [已不再建議使用](https://texfaq.org/FAQ-dolldoll)：請使用 LaTeX 的分隔符號 `\[ ... \]` 。

### 更完整的範例

以下範例示範了使用 LaTeX 排版的各類數學內容。

```latex
\documentclass{article}
\begin{document}
數學模式中的下標寫作 $a_b$，上標寫作 $a^b$。兩者可結合並巢狀使用，以撰寫如以下的表達式

\[ 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}) \]

我們使用 $\int$ 來表示積分，使用 $\frac{a}{b}$ 來表示分數。積分的上下限則透過上標與下標來放置：

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

小寫希臘字母寫作 $\omega$ $\delta$ 等，而大寫希臘字母則寫作 $\Omega$ $\Delta$。

數學運算子前面要加反斜線，例如 $\sin(\beta)$、$\cos(\alpha)$、$\log(x)$ 等。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=More+advanced+LaTeX+math+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0ASubscripts+in+math+mode+are+written+as+%24a_b%24+and+superscripts+are+written+as+%24a%5Eb%24.+These+can+be+combined+and+nested+to+write+expressions+such+as%0A%0A%5C%5B+T%5E%7Bi_1+i_2+%5Cdots+i_p%7D_%7Bj_1+j_2+%5Cdots+j_q%7D+%3D+T%28x%5E%7Bi_1%7D%2C%5Cdots%2Cx%5E%7Bi_p%7D%2Ce_%7Bj_1%7D%2C%5Cdots%2Ce_%7Bj_q%7D%29+%5C%5D%0A+%0AWe+write+integrals+using+%24%5Cint%24+and+fractions+using+%24%5Cfrac%7Ba%7D%7Bb%7D%24.+Limits+are+placed+on+integrals+using+superscripts+and+subscripts%3A%0A%0A%5C%5B+%5Cint_0%5E1+%5Cfrac%7Bdx%7D%7Be%5Ex%7D+%3D++%5Cfrac%7Be-1%7D%7Be%7D+%5C%5D%0A%0ALower+case+Greek+letters+are+written+as+%24%5Comega%24+%24%5Cdelta%24+etc.+while+upper+case+Greek+letters+are+written+as+%24%5COmega%24+%24%5CDelta%24.%0A%0AMathematical+operators+are+prefixed+with+a+backslash+as+%24%5Csin%28%5Cbeta%29%24%2C+%24%5Ccos%28%5Calpha%29%24%2C+%24%5Clog%28x%29%24+etc.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 中多種數學排版的圖片](/files/feed8f58e79ba060e376304f4338fb5da2037686)

下一個範例使用 `equation*` 環境，這是由 `amsmath` 套件，因此我們需要在文件導言區中加入以下這一行：

```latex
\usepackage{amsmath}% 用於 equation* 環境
```

如需更多關於使用 `amsmath` see [的資訊，請參閱我們的說明文章](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md).

```latex
\documentclass{article}
\usepackage{amsmath}% 用於 equation* 環境
\begin{document}
\section{第一個範例}

著名的畢氏定理 \(x^2 + y^2 = z^2\) 已被證明對其他指數不成立，這表示下一個方程式在 \(n>2\) 時沒有整數解：

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

\section{第二個範例}

這是在文字中的一個簡單數學式 \(\sqrt{x^2+1}\)。
而且這也是相同的：
\begin{math}
\sqrt{x^2+1}
\end{math}
只是改用另一個指令。

這是一個沒有編號的簡單數學式
\[\sqrt{x^2+1}\]
與文字分開。

這也一樣：
\begin{displaymath}
\sqrt{x^2+1}
\end{displaymath}

\ldots 而這個也是：
\begin{equation*}
\sqrt{x^2+1}
\end{equation*}
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=More+math+content+typeset+in+LaTeX\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%25+For+the+equation%2A+environment%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BFirst+example%7D%0A%0AThe+well-known+Pythagorean+theorem+%5C%28x%5E2+%2B+y%5E2+%3D+z%5E2%5C%29+was+proved+to+be+invalid+for+other+exponents%2C+meaning+the+next+equation+has+no+integer+solutions+for+%5C%28n%3E2%5C%29%3A%0A%0A%5C%5B+x%5En+%2B+y%5En+%3D+z%5En+%5C%5D%0A%0A%5Csection%7BSecond+example%7D%0A%0AThis+is+a+simple+math+expression+%5C%28%5Csqrt%7Bx%5E2%2B1%7D%5C%29+inside+text.+%0AAnd+this+is+also+the+same%3A+%0A%5Cbegin%7Bmath%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bmath%7D%0Abut+by+using+another+command.%0A%0AThis+is+a+simple+math+expression+without+numbering%0A%5C%5B%5Csqrt%7Bx%5E2%2B1%7D%5C%5D+%0Aseparated+from+text.%0A%0AThis+is+also+the+same%3A%0A%5Cbegin%7Bdisplaymath%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bdisplaymath%7D%0A%0A%5Cldots+and+this%3A%0A%5Cbegin%7Bequation%2A%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bequation%2A%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 中多種數學排版的圖片](/files/9bdf81ceae6a6d5363bc7d6c9e27bd86ebc98dc1)

LaTeX 的數學功能可能性無窮，因此務必造訪我們的說明頁面，以取得特定主題的建議與範例：

* [數學表達式](/latex/zh-tw/shu-xue/01-mathematical-expressions.md)
* [下標與上標](/latex/zh-tw/shu-xue/02-subscripts-and-superscripts.md)
* [中括號與小括號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md)
* [分數與二項式](/latex/zh-tw/shu-xue/05-fractions-and-binomials.md)
* [對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [運算子](/latex/zh-tw/shu-xue/07-operators.md)
* [數學模式中的間距](/latex/zh-tw/shu-xue/08-spacing-in-math-mode.md)
* [積分、求和與極限](/latex/zh-tw/shu-xue/09-integrals-sums-and-limits.md)
* [數學模式中的顯示樣式](/latex/zh-tw/shu-xue/10-display-style-in-math-mode.md)
* [希臘字母與數學符號列表](/latex/zh-tw/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [數學字型](/latex/zh-tw/shu-xue/12-mathematical-fonts.md)

## 基本文件結構

接著，我們將探討摘要，以及如何將 LaTeX 文件劃分為不同的章、節和段落。

### 摘要

科學文章通常會提供一個 *abstract* ，這是一份對其核心主題或論點的簡短概述／摘要。下一個範例示範如何使用 LaTeX 的 `abstract` 環境：

```latex
\documentclass{article}
\begin{document}
\begin{abstract}
這是一段位於
文件開頭的簡短段落。對主要主題的簡要介紹。
\end{abstract}
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=How+to+create+a+document+abstract\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Babstract%7D%0AThis+is+a+simple+paragraph+at+the+beginning+of+the+%0Adocument.+A+brief+introduction+about+the+main+subject.%0A%5Cend%7Babstract%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示以 LaTeX 排版的摘要圖片](/files/73b4d47e1197896ea67a60bed2d38c26b9e50fd0)

### 段落與換行

有了摘要之後，我們就可以開始撰寫第一個段落。下一個範例示範：

* 按兩次「enter」鍵如何建立新段落，藉由結束目前行並插入下一個空白行；
* 如何在不開始新段落的情況下開始新行，方法是使用 `\\` 命令進行手動換行，也就是雙反斜線；或者使用 `\newline` 指令。

這個範例中的第三段示範了命令 `\\` 和 `\newline`:

```latex
\documentclass{article}
\begin{document}

\begin{abstract}
這是一段位於
文件開頭的簡短段落。對主要主題的簡要介紹。
\end{abstract}

在摘要之後，我們可以開始第一段，然後按兩次「enter」來開始第二段。

這一行會開始第二段。

我將開始第三段，接著加入 \\ 手動換行，使這段文字在新行開始，但仍屬於同一段。或者，我也可以使用 \verb|\newline|\newline 命令來開始新行，而這也屬於同一段。
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+to+create+a+new+paragraph\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Babstract%7D%0AThis+is+a+simple+paragraph+at+the+beginning+of+the+%0Adocument.+A+brief+introduction+about+the+main+subject.%0A%5Cend%7Babstract%7D%0A%0AAfter+our+abstract+we+can+begin+the+first+paragraph%2C+then+press+%60%60enter%27%27+twice+to+start+the+second+one.%0A%0AThis+line+will+start+a+second+paragraph.%0A%0AI+will+start+the+third+paragraph+and+then+add+%5C%5C+a+manual+line+break+which+causes+this+text+to+start+on+a+new+line+but+remains+part+of+the+same+paragraph.+Alternatively%2C+I+can+use+the+%5Cverb%7C%5Cnewline%7C%5Cnewline+command+to+start+a+new+line%2C+which+is+also+part+of+the+same+paragraph.%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 中段落建立方式的圖片](/files/840c99a060529d1f2961b8d9e8bfe09accbc111b)

請注意 LaTeX 會自動縮排段落——除了緊接在文件標題之後，例如 section 和 subsection 之後——[如我們將會看到](#chapters-and-sections).

建議新使用者注意，多個 `\\` 或 `\newline`s 不應用來「模擬」彼此間距較大的段落，因為這可能會干擾 LaTeX 的排版演算法。建議的方法是繼續使用空白行來建立新段落，而不要使用任何 `\\`，並載入 [`parskip` 套件](https://ctan.org/pkg/parskip?lang=en) 只要加入 `\usepackage{parskip}` 到導言區。

關於段落的更多資訊可參見以下文章：

* [段落與換行](/latex/zh-tw/latex-ji-chu/02-paragraphs-and-new-lines.md)
* [如何在 LaTeX 中變更段落間距](/latex/zh-tw/ge-shi-hua/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [LaTeX 錯誤：這裡沒有可結束的行](/latex/zh-tw/latex-cuo-wu/18-latex-error-there-s-no-line-here-to-end.md) 提供了使用 `\\`.

### 章節與節

較長的文件，不論採用何種撰寫軟體，通常都會分成部分、章節、節、小節等等。LaTeX 也提供文件結構化命令，但可用的命令及其實作方式（它們的作用）可能取決於所使用的文件類別。舉例來說，使用 `book` 類別建立的文件可以分成部分、章節、節、小節等等，但 `letter` 類別並不提供（支援）任何可做到這件事的命令。

以下範例示範了根據 `book` 類別來結構化文件所使用的命令：

```latex
\documentclass{book}
\begin{document}

\chapter{First Chapter}

\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{第二節}

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

\subsection{第一小節}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section*{未編號節}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem...
\end{document}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Book+class+example+document\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cchapter%7BFirst+Chapter%7D%0A%0A%5Csection%7BIntroduction%7D%0A%0AThis+is+the+first+section.%0A%0ALorem++ipsum++dolor++sit++amet%2C++consectetuer++adipiscing++%0Aelit.+Etiam++lobortisfacilisis+sem.++Nullam+nec+mi+et+%0Aneque+pharetra+sollicitudin.++Praesent+imperdietmi+nec+ante.+%0ADonec+ullamcorper%2C+felis+non+sodales...%0A%0A%5Csection%7BSecond+Section%7D%0A%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem.++Nullam+nec+mi+et+neque+pharetra+%0Asollicitudin.++Praesent+imperdiet+mi+necante...%0A%0A%5Csubsection%7BFirst+Subsection%7D%0APraesent+imperdietmi+nec+ante.+Donec+ullamcorper%2C+felis+non+sodales...%0A%0A%5Csection%2A%7BUnnumbered+Section%7D%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem...%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX book 文件中各節的圖片](/files/0c92846e2988fc15f7b51b474c181a89120bce96)

節標題命令的名稱大多顧名思義；例如， `\chapter{First Chapter}` 會建立一個標題為下列內容的新章節： `第一章`, `\section{簡介}` 會產生一個標題為下列內容的節： `簡介`，依此類推。節還可以再細分為 `\subsection{...}` 甚至 `\subsubsection{...}`。節、小節等的編號是自動的，但可透過使用所謂的 *帶星號版本* 來停用，方法是在適當命令的結尾加上星號（\*），例如 `\section*{...}` 和 `\subsection*{...}`.

*整體而言*，LaTeX 文件類別提供以下節標題命令，而特定類別各自支援其中相關的子集：

* `\part{part}`
* `\chapter{chapter}`
* `\section{section}`
* `\subsection{subsection}`
* `\subsubsection{subsubsection}`
* `\paragraph{paragraph}`
* `\subparagraph{subparagraph}`

特別是， `\part` 和 `\chapter` 命令僅在 `報告` 和 `book` 文件類別中可用。

請參閱 Overleaf 文章 [關於節與章節的文章](/latex/zh-tw/wen-jian-jie-gou/01-sections-and-chapters.md) 以取得更多關於文件結構命令的資訊。

## 建立表格

Overleaf 提供三種建立表格的方式：

1. 使用 [**插入表格** 按鈕](/latex/zh-tw/zhi-shi-ku/067-how-to-generate-and-insert-latex-tables-in-overleaf.md#inserttable) 在 **視覺編輯器** （或 **程式碼編輯器**）工具列。
2. [從另一份文件複製並貼上表格](/latex/zh-tw/zhi-shi-ku/075-how-to-paste-formatted-content-into-overleaf.md#pastingtables) ，同時使用 **視覺編輯器**.
3. 在程式碼編輯器中撰寫表格的 LaTeX 程式碼。

如果你是 LaTeX 新手，使用 **視覺編輯器** 中的工具列（選項 1）是很好的起點——你可以在 **視覺編輯器** 和 **程式碼編輯器** 之間切換，以查看表格背後的程式碼。

這裡我們聚焦於選項 3——建立表格最靈活的方法——並提供範例，示範如何在 LaTeX 中建立表格，包括加入線條（rules）與標題。隨著你累積經驗，不妨看看我們關於 [如何使用 LaTeX 建立表格](/latex/zh-tw/tu-biao-yu-biao-ge/01-tables.md).

### 在 LaTeX 中建立基本表格

我們先從一個示範如何排版基本表格的例子開始：

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

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+example+of+a+basic+table\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7Bc+c+c%7D%0A+cell1+%26+cell2+%26+cell3+%5C%5C+%0A+cell4+%26+cell5+%26+cell6+%5C%5C++%0A+cell7+%26+cell8+%26+cell9++++%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D%0A%3C%2Fsource%3E)

此範例會產生以下輸出：

![顯示以 LaTeX 排版之表格的圖片](/files/3065f6ef8ae49a375c90944df02d976f35ede9ae)

該 `tabular` 環境是建立表格的預設 LaTeX 方法。你必須為此環境指定一個參數，在此例中為 `{c c c}` ，它告知 LaTeX 會有三欄，且每一欄中的文字都必須置中。你也可以使用 `r` 來將文字靠右對齊，而使用 `l` 來將其靠左對齊。對齊符號 `&` 用來分隔表格列中的各個儲存格。要結束一列，請使用 *換行* 指令 `\\`。我們的表格包含在一個 `center` 環境中，使其在頁面文字寬度內置中。

### 加入邊框

該 `tabular` 環境支援將水平與垂直線（rules）作為表格的一部分：

* 要加入水平線，放在列的上方與下方，請使用 `\hline` 指令
* 要加入垂直線，放在欄與欄之間，請使用垂直線參數 `|`

在此範例中，參數是 `{|c|c|c|}` ，它宣告了三欄（置中）且每欄之間以垂直線（rule）分隔；此外，我們使用 `\hline` 在第一列上方與最後一列下方放置水平線：

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

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+example+with+rules\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B%7Cc%7Cc%7Cc%7C%7D+%0A+%5Chline%0A+cell1+%26+cell2+%26+cell3+%5C%5C+%0A+cell4+%26+cell5+%26+cell6+%5C%5C+%0A+cell7+%26+cell8+%26+cell9+%5C%5C+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示一個包含水平線與垂直線之以 LaTeX 排版的表格的圖片](/files/09c0ec3a9160a52a3a292ae46ce03a60222d6a8e)

以下是另一個範例：

```latex
\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 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+table+example+containing+rules\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A+%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+%5Chline%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+%5Chline%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+%5Chline%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+%5Chline%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示一個包含水平線與垂直線之以 LaTeX 排版的表格的圖片](/files/b2a2eb6af9dbffdd44c371bd91b98c6cd21c62a1)

### 標題、標籤與參照

你可以像圖片一樣為表格加上標題與參照。唯一的差別是，不是使用 **`figure`** 環境，而是使用 **`table`** 環境中。

```latex
Table \ref{table:data} 顯示如何加入表格標題並參照表格。
\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{用於測試標題與標籤的表格。}
\label{table:data}
\end{table}
```

[在 Overleaf 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+captions+and+references\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0ATable+%5Cref%7Btable%3Adata%7D+shows+how+to+add+a+table+caption+and+reference+a+table.%0A%5Cbegin%7Btable%7D%5Bh%21%5D%0A%5Ccentering%0A%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Ccaption%7BTable+to+test+captions+and+labels.%7D%0A%5Clabel%7Btable%3Adata%7D%0A%5Cend%7Btable%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![含有標題的 LaTeX 表格](/files/14b41824f5cf01544a9729fcda346830beba9601)

## 新增目錄

建立目錄很簡單，因為命令 `\tableofcontents` 幾乎已經替你完成所有工作：

```latex
\documentclass{article}
\title{章節與章}
\author{Gubert Farnsworth}
\date{2022 年 8 月}
\begin{document}

\maketitle

\tableofcontents

\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*{未編號節}
\addcontentsline{toc}{section}{未編號節}

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

\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 中開啟此範例。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Generating+a+table+of+contents\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Ctitle%7BSections+and+Chapters%7D%0A%5Cauthor%7BGubert+Farnsworth%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A++%0A%5Cmaketitle%0A++%0A%5Ctableofcontents%0A%0A%5Csection%7BIntroduction%7D%0A+++%0AThis+is+the+first+section.%0A++++++%0ALorem++ipsum++dolor++sit++amet%2C++consectetuer++adipiscing++%0Aelit.+++Etiam++lobortisfacilisis+sem.++Nullam+nec+mi+et+%0Aneque+pharetra+sollicitudin.++Praesent+imperdietmi+nec+ante.+%0ADonec+ullamcorper%2C+felis+non+sodales...%0A+++++++%0A%5Csection%2A%7BUnnumbered+Section%7D%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BUnnumbered+Section%7D%0A%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem.++Nullam+nec+mi+et+neque+pharetra+%0Asollicitudin.++Praesent+imperdiet+mi+necante...%0A%0A%5Csection%7BSecond+Section%7D%0A+++++++%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem.++Nullam+nec+mi+et+neque+pharetra+%0Asollicitudin.++Praesent+imperdiet+mi+necante...%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示 LaTeX 產生之目錄的圖片](/files/e456ad15eceb4e66420d040981b7b41ac66aba87)

節、小節與章會自動收錄到目錄中。若要手動加入項目，例如未編號節，請使用命令 `\addcontentsline` ，如範例所示。

## 下載你完成的文件

以下短片示範如何下載你專案的原始碼或排版後的 PDF 檔：

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/2n6iw0AUELNtABCuva0oV5/cf27bff3a6099da94362d64645e69dfe/LL30download.mp4>" %}

更多資訊可參見 Overleaf 說明文章 [從 Overleaf 匯出你的作品](/latex/zh-tw/zhi-shi-ku/036-exporting-your-work-from-overleaf.md).

## 尋找與使用 LaTeX 套件

LaTeX 不僅提供強大的排版能力，還提供了 *可擴充性的架構* ，透過使用附加 *套件*。與其試圖提供那些「想要包辦一切」的命令與功能，LaTeX 的設計是 *可擴充的*，讓使用者可以載入外部程式碼（套件）以提供更專門的排版能力，或延伸 LaTeX 內建功能——例如表格排版。如同在章節中所觀察到的 [加入圖片](#adding-images)，而 `graphicx` 套件透過提供匯入圖形檔案的命令來延伸 LaTeX，並且是（在導言區）透過撰寫

```latex
\usepackage{graphicx}
```

### 載入套件

如上所述，套件是透過 `\usepackage` 命令在文件導言區中載入，但由於（許多）LaTeX 套件提供了一組 *選項*，可用來設定其行為，因此 `\usepackage` 命令常常長得像這樣：

```latex
\usepackage[options]{somepackage}
```

方括號「`[...]`」會告知 LaTeX 在載入 `somepackage`時應套用哪一組選項。在使用者所要求的選項集合中，個別選項或設定通常以逗號分隔；例如， [`geometry` 套件](https://ctan.org/pkg/geometry) 提供了許多可用來設定 LaTeX 中頁面版面配置的選項，因此通常會這樣使用 `geometry` 可能會長得像這樣：

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

該 `geometry` 套件是一個由全球 LaTeX 社群成員編寫並貢獻的套件範例，並且免費提供給任何想使用的人。

如果某個 LaTeX 套件沒有提供任何選項，或使用者想使用該套件選項的預設值，則可這樣載入：

```latex
\usepackage{somepackage}
```

當你在 `\usepackage[...]{somepackage}` LaTeX 會尋找名為 `*somepackage*.sty`的對應檔案，它需要載入並處理該檔案——以使套件命令可用，並執行該套件提供的任何其他程式碼。如果 LaTeX 找不到 `*somepackage*.sty` 它，便會以錯誤終止，如以下 Overleaf 範例所示：

```latex
\documentclass[12pt, letterpaper]{article}
\usepackage{somepackage}% 一個不存在的套件
\begin{document}
這會失敗！
\end{document}
```

[在 Overleaf 中開啟這個 ***產生錯誤的範例*** 在 Overleaf 上](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Error+due+to+missing+package\&snip=%5Cdocumentclass%5B12pt%2C+letterpaper%5D%7Barticle%7D%0A%5Cusepackage%7Bsomepackage%7D%25+a+NON-EXISTENT+package%0A%5Cbegin%7Bdocument%7D%0AThis+will+fail%21%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![顯示由缺少套件所導致錯誤的圖片](/files/22437f1bdb18c6bd3a07c5cac5ca6b5d67931363)

### 尋找關於套件的資訊：CTAN

套件透過 [Comprehensive TeX Archive Network](https://www.ctan.org/)發行，通常簡稱為 CTAN，截至撰寫時，該網路收錄了 2881 位貢獻者提供的 6287 個套件。CTAN [自稱為](https://www.ctan.org/ctan) 寫成

> ... 一組遍布世界各地、提供可下載 TEX 相關材料的網際網路網站。

你可以瀏覽 CTAN 來尋找有用的套件；例如：

* [依主題](https://www.ctan.org/topics/cloud)
* [按字母順序](https://www.ctan.org/pkg) （如果你知道套件名稱，這會很有用）

你也可以使用 [搜尋功能](https://www.ctan.org/pkg) （位於頁面頂端）。

### Overleaf 上可用的套件：介紹 TeX Live

每年一次，會將（大量） *子集* 的 CTAN 套件，以及 LaTeX 相關字型與其他軟體，彙整並發行為一個名為 [TeX Live](https://tug.org/texlive/)的系統，可用來安裝你自己的（本機）LaTeX 環境。事實上， [Overleaf 的伺服器也使用 TeX Live](/latex/zh-tw/lei-bie-dang/02-overleaf-and-tex-live.md) ，並會在 TeX Live 發布新版本時更新。Overleaf 的 TeX Live 更新並非立即進行，而是在發布後數個月才進行，讓我們有時間針對新版本 TeX Live 與 [收錄於我們圖庫中的數千個範本](https://www.overleaf.com/gallery)進行相容性測試。例如，這裡是我們的 [TeX Live 2025 升級公告](https://www.overleaf.com/blog/tex-live-2025-is-now-available).

雖然 TeX Live 包含（大量） *子集* CTAN 套件的 [`igo` 用於排版圍棋圖](https://ctan.org/pkg/igo?lang=en)，它託管在 CTAN 上但未包含在 TeX Live（發行的內容）中，因此在 Overleaf 上無法使用。CTAN 上託管的某些套件並非 TeX Live 的一部分，原因很多：也許某套件已過時、有授權問題、非常新（最近才上傳），或有平台相依性，例如可在 Windows 上運作但不能在 Linux 上運作。

新套件與既有套件的更新會全年上傳至 CTAN，但 TeX Live 的更新則按年發行；因此，當前版本 TeX Live 中的套件不會像 CTAN 上託管的那些那樣即時。由於 Overleaf 的伺服器使用 TeX Live，因此安裝在我們伺服器上的套件——也就是我們使用者可用的套件——可能不會是 CTAN 上可取得的最新版本，但一般而言，這不太可能造成問題。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
