The geometry package

Sets the paper size and the page margins with options such as margin=2.5cm, left, top and a4paper.

Loading the package

\usepackage[margin=2.5cm]{geometry}

Without a package, the margins follow from lengths such as \oddsidemargin, \textwidth and \topmargin, which are measured from a point one inch inside the paper edge. geometry takes the margins you want and computes these lengths.

You give only part of the layout, for example the four margins, and the package derives the text width and height from the paper size. The options go into \usepackage[...]{geometry} or into \geometry{...} in the preamble.

The header and footer are placed inside the top and bottom margin. With includehead and includefoot they count as part of the text area.

Main commands

margin=2.5cmThe same margin on all four sides.
left=3cm, right=2cm, top=2.5cm, bottom=2cmOne value per side. In a two-sided document left is the inner margin and right the outer one.
a4paper, landscapePaper size and orientation. A paper size given as class option is used as well.
bindingoffset=1cmExtra space on the binding side, added to the inner margin.
headheight=14ptHeight of the header line; raise it when fancyhdr warns that \headheight is too small.
showframeDraws the text area, header, footer and margin note area as frames, for checking the layout.
\newgeometry{margin=1.5cm}Changes the margins inside the document and starts a new page.
\restoregeometryReturns to the layout from the preamble, again on a new page.

Complete example

\documentclass[a4paper]{article}
\usepackage[left=3cm, right=2.5cm, top=2.5cm, bottom=2cm]{geometry}
\begin{document}
\section{Margins}
This page has a left margin of 3\,cm and a right margin of 2.5\,cm.

\newgeometry{margin=1.5cm}
\section{Wide page}
From here on all four margins are 1.5\,cm wide.

\restoregeometry
\section{Back to the preamble layout}
The margins from the preamble apply again.
\end{document}
Result
Page 1 of the compiled examplePage 1
Page 2 of the compiled examplePage 2
Page 3 of the compiled examplePage 3

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages