> 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/ge-shi-hua/07-page-size-and-margins.md).

# 頁面大小與頁邊距

## 簡介

LaTeX 文件中的頁面尺寸具有高度可設定性，而 [`geometry` 套件](https://ctan.org/pkg/geometry?lang=en) 提供了一種簡單的方法來變更不同元素的長度與版面配置，例如紙張大小、邊界、註腳、頁首、方向等。

### 範例

假設你需要建立一份使用 A4 紙張、文字區域寬度不超過 6 英吋且高度不超過 8 英吋的文件。你可以只在 LaTeX 前言中加入這一行，就輕鬆建立這樣的文件：

```latex
\usepackage[a4paper, total={6in, 8in}]{geometry}
```

傳入 `geometry` 套件的參數值會產生我們所需的版面配置。在這個例子中， `a4paper` 設定了所需的 A4 紙張大小，而傳入 `總` 參數的值決定了文字區域的大小。請注意，Overleaf 使用歐洲版的 LaTeX 發行版，因此預設會產生 A4 大小的文件。

```latex
\documentclass{article}
\usepackage{blindtext}
\usepackage[a4paper, total={6in, 8in}]{geometry}

\begin{document}
\section{簡介}
這是一份測試文件，使用 A4 紙張以及使用者自訂的文字區域。
\subsection{一些範例文字}
\blindtext[8]

\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+geometry+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%5Ba4paper%2C+total%3D%7B6in%2C+8in%7D%5D%7Bgeometry%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AThis+is+a+test+document+which+uses+A4-sized+paper+and+the+user-defined+text+area.+%0A%5Csubsection%7BSome+dummy+text%7D%0A%5Cblindtext%5B8%5D%0A%0A%5Cend%7Bdocument%7D)

## 紙張大小、方向與邊界

修改文件的紙張大小、方向與邊界是一項常見需求，使用 `geometry` 套件即可輕鬆完成。設定所需值有兩種方式：

* 將它們作為參數提供給 `\usepackage` 敘述，如上面的範例所示，或者
* 使用 `\geometry` 命令放在前言中。

例如，讓我們建立一份紙張大小為 legal、橫向排版且邊界為 2 英吋的文件：

```latex
\usepackage[legalpaper, landscape, margin=2in]{geometry}
```

你也可以用稍微不同的方式達成相同效果：

```latex
\usepackage{geometry}
\geometry{legalpaper, landscape, margin=2in}
```

如你所見，參數以逗號分隔。完整的預定義紙張大小清單請見 [參考指南](#reference-guide)。第二個參數是方向，其預設值為 `直向`。最後，每個 `邊界` 都設為 `2in`.

## 微調你的 LaTeX 頁面尺寸

### 視覺化版面配置

該 [`版面配置` 套件](https://ctan.org/pkg/layout?lang=en) 提供了一個非常方便的解決方案，用於 *視覺化* 文件目前的版面配置，以及決定該版面配置的各種 LaTeX 參數值。它提供兩個命令： `版面配置` 和 `layout*` ，可繪製代表目前版面的圖形。加星號的版本（`layout*`）會重新計算用於繪製圖形的內部值；如果你變更了 LaTeX 的頁面版面配置參數，這會很有用。以下是範例：

```latex
\documentclass{article}
\usepackage{layout}
\begin{document}
\section{預設的 \LaTeX{} 版面配置}
以下是預設版面配置：

\vspace{10pt}
\layout
\section{做一些變更}
變更邊註設定，並使用命令 \verb|layout*| 重新繪製頁面版面配置圖：
\vspace{10pt}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparsep}{0pt}

\layout*
\end{document}
```

[在 Overleaf 中開啟這個範例以查看結果！](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+layout+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Blayout%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BDefault+%5CLaTeX%7B%7D+layout%7D%0AHere%27s+the+default+layout%3A%0A%0A%5Cvspace%7B10pt%7D%0A%5Clayout%0A%5Csection%7BMake+some+changes%7D%0AMake+changes+to+the+margin+paragraph+settings+and+use+the+command+%5Cverb%7Clayout%2A%7C+to+redraw+the+page+layout+diagram%3A%0A%5Cvspace%7B10pt%7D%0A%5Csetlength%7B%5Cmarginparwidth%7D%7B0pt%7D%0A%5Csetlength%7B%5Cmarginparsep%7D%7B0pt%7D%0A%0A%5Clayout%2A%0A%5Cend%7Bdocument%7D)

下圖顯示了由 `版面配置` 套件。

![Layout-dimensions.png](/files/049eab73a65792c88345e0c8eb374d8c21d4ba2c)

### 使用 geometry 套件的版面配置參數

該 `geometry` 套件提供了一個介面，讓你使用名稱直觀的參數來變更頁面尺寸，這些參數需要寫成 `parameter=value`的形式，並使用標準 LaTeX 單位（mm、cm、pt、in）。以下清單會引用上一節提供的頁面版面配置圖。

**textwidth**

對應圖中的元素 8。

**textheight**

圖中的元素 7。

**總**

取決於其他參數，預設定義為正文的尺寸，但可以與 includehead、includefoot、includeheadfoot 和 includemp 命令結合，以同時變更頁首、正文、頁尾與邊註的尺寸。

**left、lmargin、inner**

這三個參數會變更左邊界的長度。圖中的元素 1 與 3 合併。

**right、rmargin、outer**

這三個參數會變更右邊界的長度。圖中的元素 9 與 10 合併。

**top、tmargin**

這兩個參數代表圖中的元素 2 與 6，合併。

**bottom、bmargin**

這兩個參數設定文件底緣到其基線的距離。

**headheight**

頁首高度

**headsep**

頁首（基線）與正文之間的間距。圖中的元素 6。

**footnotesep**

正文底部（基線）與註腳文字頂端之間的間距。

**footskip**

正文最後一行的基線與頁尾基線之間的距離。

**marginparwidth、marginpar**

邊註的寬度。圖中的元素 10。

紙張大小可以透過命令設定為你需要的任何尺寸 `papersize={⟨width⟩,⟨height⟩}`.

讓我們來看看前述部分選項的範例：

```latex
\documentclass{article}
\usepackage{blindtext}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }
\begin{document}
\section{一些範例文字}
\blindtext[10]
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+geometry+package+layout+parameters\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%7Bgeometry%7D%0A+%5Cgeometry%7B%0A+a4paper%2C%0A+total%3D%7B170mm%2C257mm%7D%2C%0A+left%3D20mm%2C%0A+top%3D20mm%2C%0A+%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BSome+dummy+text%7D%0A%5Cblindtext%5B10%5D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![使用 geometry 套件](/files/02d88513f2b03191bf4c9e2f71490b91cf0bfc22)

在這裡，文字區域、左邊界與上邊界已設定。右邊界與下邊界會自動計算以符合頁面。

## 參考指南

| 參數        | 說明     | 值                                                                                                                                                                                                                                                                                                                              |
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| papersize | 決定紙張大小 | a0paper, a1paper, a2paper, a3paper, a4paper, a5paper, a6paper,b0paper, b1paper, b2paper, b3paper, b4paper, b5paper, b6paper,c0paper, c1paper, c2paper, c3paper, c4paper, c5paper, c6paper,b0j, b1j, b2j, b3j, b4j, b5j, b6j,ansiapaper, ansibpaper, ansicpaper, ansidpaper, ansiepaper,letterpaper, executivepaper, legalpaper |

## 延伸閱讀

詳情請見：

* [LaTeX 中的長度](/latex/zh-tw/ge-shi-hua/01-lengths-in-latex.md)
* [頁首與頁尾](/latex/zh-tw/ge-shi-hua/02-headers-and-footers.md)
* [多欄排版](/latex/zh-tw/ge-shi-hua/09-multiple-columns.md)
* [腳註](/latex/zh-tw/ge-shi-hua/14-footnotes.md)
* [頁碼編排](/latex/zh-tw/ge-shi-hua/03-page-numbering.md)
* [文字對齊](/latex/zh-tw/ge-shi-hua/06-text-alignment.md)
* [超連結](/latex/zh-tw/wen-jian-jie-gou/09-hyperlinks.md)
* [了解套件與類別檔](/latex/zh-tw/lei-bie-dang/01-understanding-packages-and-class-files.md)
* [撰寫你自己的套件](/latex/zh-tw/lei-bie-dang/03-writing-your-own-package.md)
* [撰寫你自己的 class](/latex/zh-tw/lei-bie-dang/04-writing-your-own-class.md)
* [geometry 套件文件](http://mirrors.ctan.org/macros/latex/contrib/geometry/geometry.pdf).


---

# 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/ge-shi-hua/07-page-size-and-margins.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.
