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.5cm | The same margin on all four sides. |
left=3cm, right=2cm, top=2.5cm, bottom=2cm | One value per side. In a two-sided document left is the inner margin and right the outer one. |
a4paper, landscape | Paper size and orientation. A paper size given as class option is used as well. |
bindingoffset=1cm | Extra space on the binding side, added to the inner margin. |
headheight=14pt | Height of the header line; raise it when fancyhdr warns that \headheight is too small. |
showframe | Draws 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. |
\restoregeometry | Returns 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}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
\geometry{...}works only in the preamble; after\begin{document}it stops with Can be used only in preamble. Use\newgeometrythere.\newgeometrycannot change the paper size or the orientation. For single landscape pages see Rotate a single page to landscape in LaTeX.- In a KOMA-Script class,
geometryreplaces the layout that the class computes fromDIVandBCOR. Use one of the two, not both.
Related pages
- How-to Set page margins in LaTeX
- How-to Set paper size and orientation in LaTeX
- How-to Rotate a single page to landscape in LaTeX
- Package
fancyhdr - How-to Write a CV in LaTeX
- How-to Set up a thesis in LaTeX