Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 38 ยท Documents and Text Formatting

Page Layout and Margins with geometry

Control paper size, margins, orientation, columns, headers, footers and page numbering in LaTeX with the geometry, multicol and fancyhdr packages, with working examples.

The default LaTeX page has generous margins and a text block that is a bit narrow by modern standards. Changing margins, paper size or columns is one of the first customizations everyone makes. The good news: you rarely touch the low-level dimensions. A few packages cover almost every need.

The page at a glance

A printed page is a set of nested boxes. The paper contains the text body (where your paragraphs go) surrounded by margins; above and below the body are the header and footer, and a marginal note column can sit beside it.

LaTeX stores these sizes in lengths you can read and set, such as \textwidth (width of the body), \textheight, \paperwidth, \oddsidemargin and \topmargin. Setting them by hand is error-prone because they depend on each other, and an offset of one inch is built in. That is why the geometry package exists.

Margins with geometry

Load it in the preamble. Options can be passed in the \usepackage line or set later with \geometry{...}.

LATEX
\usepackage[a4paper, margin=2.5cm]{geometry}
Option Meaning
a4paper, letterpaper, a5paper Paper size
landscape Rotated paper
margin=2.5cm All four margins
left=3cm, right=2cm Individual margins
top=2cm, bottom=3cm Vertical margins
hmargin=3cm, vmargin=2cm Horizontal and vertical pairs
inner=3cm, outer=2cm Mirrored margins in two-sided documents
bindingoffset=1cm Extra inner margin for binding
textwidth=15cm, textheight=22cm Set the text body instead
includeheadfoot Count header and footer as part of the body
showframe Draw the layout boxes, useful for debugging

A handy habit while tuning: add showframe and look at the PDF. When you are done, remove it.

Compare margin settings in the stand-in below. It draws an A4 page to scale with your margins and tells you the resulting text width. It is a drawing aid, not LaTeX, but the arithmetic is exactly what geometry does.

Margins on an A4 page (stand-in)

Several columns

For two columns across the whole document use the class option twocolumn. For columns in only part of the document, use the multicol package:

LATEX
\usepackage{multicol}

\begin{multicols}{2}
  This text flows through two balanced columns. The package
  balances the column heights on the last page of the block.
\end{multicols}

You can set the gap with \setlength{\columnsep}{1cm} and draw a rule between columns with \setlength{\columnseprule}{0.4pt}. Floats such as figures and tables inside multicols have limits; use the starred figure* and table* forms in twocolumn documents to span both columns.

Headers, footers and page numbers

Page numbers are controlled by page styles:

LATEX
\pagestyle{plain}       % number centered in the footer (the default)
\pagestyle{empty}       % no header or footer
\pagestyle{headings}    % running headers from sections
\thispagestyle{empty}   % only for the current page
\pagenumbering{roman}   % i, ii, iii ... (arabic, Roman, alph also work)
\setcounter{page}{1}    % restart numbering

For anything custom, use fancyhdr:

LATEX
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}                         % clear all header and footer fields
\fancyhead[L]{My Thesis}           % left of the header
\fancyhead[R]{\leftmark}           % right: current chapter or section name
\fancyfoot[C]{\thepage}            % centered page number
\renewcommand{\headrulewidth}{0.4pt}

The letters L, C, R mean left, center and right; E and O mean even and odd pages in two-sided documents. \leftmark and \rightmark hold chapter and section titles. If LaTeX warns "\headheight is too small", add \setlength{\headheight}{14pt} (or the size it recommends).

Page breaks and flow

You usually let LaTeX decide where pages end. When you must intervene:

Command Effect
\newpage End the current page here
\clearpage End the page and flush all pending figures and tables
\pagebreak[n] Suggest a break, n from 0 (weak) to 4 (mandatory)
\nopagebreak Discourage a break
\newpage in two-column mode Moves to the next column
\cleardoublepage Next odd page, for books
\samepage Try to keep a block on one page
\raggedbottom Allow uneven page bottoms instead of stretching spaces

Avoid using \newpage to polish layout before the text is final. Text changes will move everything and your manual breaks will leave half-empty pages.

Landscape pages

A single wide table or figure may need a rotated page. The pdflscape package provides:

LATEX
\usepackage{pdflscape}

\begin{landscape}
  % wide table here
\end{landscape}

The PDF viewer shows the page rotated, which is exactly what you want for a wide table.

A reusable layout block

LATEX
\documentclass[11pt,a4paper]{article}
\usepackage[margin=2.5cm, headheight=14pt]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Report}
\fancyfoot[C]{Page \thepage}
\begin{document}
...
\end{document}

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which package makes it easy to set margins and paper size?

    geometry accepts options such as a4paper and margin=2.5cm.
  2. 2. What does \pagestyle{empty} do?

    The empty page style prints nothing in the header or footer.
  3. 3. Which is the right tool for columns in only one part of a document?

    twocolumn applies to the whole document; multicols can start and stop anywhere.
  4. 4. What is the difference between \newpage and \clearpage?

    \clearpage forces floats that are waiting to be placed before the page ends.

Summary

  • Use geometry for paper size and margins; add showframe to see the boxes.
  • twocolumn makes the whole document two-column; multicols is for local columns.
  • fancyhdr builds custom headers and footers; \pagestyle, \thispagestyle and \pagenumbering control numbering.
  • Leave page breaks to LaTeX until the text is final; use \clearpage to flush floats.
  • pdflscape gives landscape pages for wide material.

Next: Special Characters, Accents and Symbols