Set page margins in LaTeX (geometry)
Load the geometry package with the margins as options: \usepackage[margin=2.5cm]{geometry} sets all four margins to 2.5 cm.
The same margin on all sides
margin sets the left, right, top and bottom margin at once. a4paper sets the paper size; without a paper option the standard classes lay out the page for US letter.
This goes into the preamble.
\usepackage[a4paper, margin=2.5cm]{geometry}A different margin on each side
left, right, top and bottom set one margin each. hmargin=3cm sets left and right together, vmargin=2cm top and bottom. The header and the footer sit inside the top and bottom margin.
This goes into the preamble.
\usepackage[a4paper, left=3cm, right=2.5cm, top=2.5cm, bottom=2cm]{geometry}Margins for two-sided printing
With twoside, inner is the margin at the spine and outer the margin at the open edge; they swap between odd and even pages. bindingoffset adds the strip that disappears in the binding.
This goes into the preamble.
\usepackage[a4paper, twoside, inner=3cm, outer=2cm, bindingoffset=5mm]{geometry}Other margins for a few pages
\newgeometry{...} starts a new page with the margins you give, and \restoregeometry starts another new page with the margins from the preamble.
Complete document:
\documentclass[a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
Text with the margins from the preamble.
\newgeometry{margin=1cm}
A page with narrow margins, for example for a wide table.
\restoregeometry
Text with the margins from the preamble again.
\end{document}Pitfalls
- Loading
geometrya second time with other options stops with an option clash. Load it once and change the values later with\geometry{margin=2cm}in the preamble. \newgeometrychanges margins only. The paper size and the orientation stay as set in the preamble.- With a KOMA-Script class,
geometryreplaces the type area that the class calculates from itsDIVoption.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
geometry - How-to Set paper size and orientation in LaTeX
- How-to Headers and footers in LaTeX
- Error Option clash for package geometry