> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/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{Introduction}
这是一个测试文档，使用了 A4 纸张和用户定义的文本区域。
\subsection{Some dummy text}
\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` 命令放在导言区中。

例如，我们来创建一个具有法律纸张大小、横向排版和 2 英寸页边距的文档：

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

你也可以用略有不同的方式实现同样的效果：

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

如你所见，这些参数之间用逗号分隔。有关预定义纸张大小的完整列表，请参见 [参考指南](#reference-guide)。第二个参数是方向，其默认值是 `portrait`。最后，每个 `页边距` 都设置为 `2in`.

## 微调你的 LaTeX 页面尺寸

### 可视化布局

该 [`布局` 宏包](https://ctan.org/pkg/layout?lang=en) 为 *可视化* 文档当前的布局，以及决定该布局的各种 LaTeX 参数值，提供了一个非常方便的解决方案。它提供两个命令： `布局` 和 `layout*` ，用于绘制表示当前布局的图形。带星号的版本（`layout*`）会重新计算用于绘制该图形的内部值；如果你修改了 LaTeX 的页面布局参数，这会很有用。下面是一个示例：

```latex
\documentclass{article}
\usepackage{layout}
\begin{document}
\section{Default \LaTeX{} layout}
这是默认布局：

\vspace{10pt}
\layout
\section{Make some changes}
修改页边注的设置，并使用命令 \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/f23d12025c26a24a022afca27b97f6e108f61a5a)

### 使用 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{Some dummy text}
\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/8384c709e6ba21c6379a82a4c575ba434cfba8d5)

这里设置了文本区域、左边距和上边距。右边距和下边距会自动计算以适配页面。

## 参考指南

| 参数        | 说明     | 取值                                                                                                                                                                                                                                                                                                                             |
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 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-cn/ge-shi-hua/01-lengths-in-latex.md)
* [页眉和页脚](/latex/zh-cn/ge-shi-hua/02-headers-and-footers.md)
* [多栏排版](/latex/zh-cn/ge-shi-hua/09-multiple-columns.md)
* [脚注](/latex/zh-cn/ge-shi-hua/14-footnotes.md)
* [页码编号](/latex/zh-cn/ge-shi-hua/03-page-numbering.md)
* [文本对齐](/latex/zh-cn/ge-shi-hua/06-text-alignment.md)
* [超链接](/latex/zh-cn/wen-dang-jie-gou/09-hyperlinks.md)
* [理解宏包和类文件](/latex/zh-cn/lei-wen-jian/01-understanding-packages-and-class-files.md)
* [编写你自己的宏包](/latex/zh-cn/lei-wen-jian/03-writing-your-own-package.md)
* [编写自己的类](/latex/zh-cn/lei-wen-jian/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://ayakaleaf-pro.ayaka.space/latex/zh-cn/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.
