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

# Page size and margins

## Introduction

The page dimensions in a LaTeX document are highly configurable and the [`geometry` package](https://ctan.org/pkg/geometry?lang=en) offers a simple way to change the length and layout of different elements such as the paper size, margins, footnote, header, orientation, etc.

### Example

Suppose you need to create a document using A4-sized paper with a text area which shouldn't exceed 6 inches wide and 8 inches high. You can easily create such a document by including this line in your LaTeX preamble:

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

The parameter values passed to the `geometry` package produce our required layout. In this case, `a4paper` establishes the desired A4 paper size and values supplied to the `total` parameter determine the size of the text area. Note that Overleaf uses a European LaTeX distribution, which produces documents in A4 size by default.

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

\begin{document}
\section{Introduction}
This is a test document which uses A4-sized paper and the user-defined text area.
\subsection{Some dummy text}
\blindtext[8]

\end{document}
```

[Open this example in 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)

## Paper size, orientation and margins

Modifying a document's paper size, orientation and margins is a common requirement which can easily be achieved using the `geometry` package. There are two ways to set the desired values:

* provide them as parameters to the `\usepackage` statement as in the example above, or
* use the `\geometry` command in the preamble.

For example, let's create a document with legal paper size, landscape orientation and a 2 in margin:

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

You can achieve the same thing in a slightly different way:

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

As you see, the parameters are comma separated. For a complete list of predefined paper sizes, see the [reference guide](#reference-guide). The second parameter is the orientation, its default value is `portrait`. Finally, each `margin` is set to `2in`.

## Fine tuning your LaTeX page dimensions

### Visualizing the layout

The [`layout` package](https://ctan.org/pkg/layout?lang=en) provides a very convenient solution to *visualizing* the document's current layout—and the values of various LaTeX parameters which determine that layout. It provides two commands: `layout` and `layout*` which draw a graphic representing the current layout. The starred version (`layout*`) recalculates the internal values used to draw the graphic, which can be useful if you make changes to LaTeX's page-layout parameters. Here is an example:

```latex
\documentclass{article}
\usepackage{layout}
\begin{document}
\section{Default \LaTeX{} layout}
Here's the default layout:

\vspace{10pt}
\layout
\section{Make some changes}
Make changes to the margin paragraph settings and use the command \verb|layout*| to redraw the page layout diagram:
\vspace{10pt}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparsep}{0pt}

\layout*
\end{document}
```

[Open this example in Overleaf to view the results!](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)

The following image shows an example of the graphic produced by the `layout` package.

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

### Using the geometry package layout parameters

The `geometry` package provides an interface to change page dimensions using intuitively-named parameters which need to be written in the form `parameter=value`, using standard LaTeX units (mm, cm, pt, in). The following list makes reference to the page-layout graphic provided in the previous section.

**textwidth**

Corresponds to element 8 in the graphic.

**textheight**

Element 7 in the graphic.

**total**

Depends on other parameters, by default defines the dimensions of the Body, but can be combined with the includehead, includefoot, includeheadfoot and includemp commands to change the dimensions of Header, the Body, the Footer and the Margin Notes altogether.

**left, lmargin, inner**

These three parameters change the length of the left margin. Elements 1 and 3 in the graphic, combined.

**right, rmargin, outer**

These three parameters change the length of the right margin. Elements 9 and 10 in the graphic, combined.

**top, tmargin**

These two parameters represent elements 2 and 6 in the graphic, combined.

**bottom, bmargin**

These two parameters set the distance from the bottom edge of the document to its baseline.

**headheight**

Height of the header

**headsep**

Separation between header (baseline) and text body. Element 6 in the graphic.

**footnotesep**

Separation between the bottom of text body (baseline) and the top of footnote text.

**footskip**

Distance separation between baseline of last line of text and baseline of footer.

**marginparwidth, marginpar**

Width of the margin notes. Element 10 in the graphic.

The paper size can be set to any size you need by means of the command `papersize={⟨width⟩,⟨height⟩}`.

Let's see an example with some of the aforementioned options:

```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}
```

[Open this example in 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)

This example produces the following output:

![Using the geometry package](/files/zUijfsnr5zzFUVNH0Dkq)

Here the text area, the left margin and the top margin are set. The right and bottom margins are automatically computed to fit the page.

## Reference guide

| parameter | description                      | values                                                                                                                                                                                                                                                                                                                         |
| --------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| papersize | Determines the size of the paper | 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 |

## Further reading

For more information see:

* [Lengths in LaTeX](/latex/formatting/01-lengths-in-latex.md)
* [Headers and footers](/latex/formatting/02-headers-and-footers.md)
* [Multiple columns](/latex/formatting/09-multiple-columns.md)
* [Footnotes](/latex/formatting/14-footnotes.md)
* [Page numbering](/latex/formatting/03-page-numbering.md)
* [Text alignment](/latex/formatting/06-text-alignment.md)
* [Hyperlinks](/latex/document-structure/09-hyperlinks.md)
* [Understanding packages and class files](/latex/class-files/01-understanding-packages-and-class-files.md)
* [Writing your own package](/latex/class-files/03-writing-your-own-package.md)
* [Writing your own class](/latex/class-files/04-writing-your-own-class.md)
* [The geometry package documentation](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/formatting/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.
