> 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-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{引言}
这是一个测试文档，使用了 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)。第二个参数是方向，其默认值是 `纵向`。最后，每个 `边距` 都设置为 `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/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://overleaf-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.
