Contents

Setting Page Margins

When writing a document in LaTeX\LaTeX, page margins should be defined early so the printed result matches the intended layout. A page margin is the empty space between the document content and the edge of the paper.

Document classes such as article already provide default margin settings. If you want to inspect that layout, you can use the layout package.

\documentclass{article}
\usepackage{layout}
\begin{document}
\layout
\end{document}

The compiled result will show the page layout information.

[

Page layout information
Page layout information
](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG51xH00P8rDCcBfvbC14in7vUuhDeOPPDsVWoWDmfmmlFsS8S6ct653uNvzd4VxDKZ7MBhWQTTJ2DiO0ifgGq5PhAvISehYPoB5w4FSBOLpEUPlIUQYtPFgI9BfHcFQc67rrYMDFSC7g/s2048/0001+%252817%2529.jpg)

To set the top, left, bottom, and right margins directly, the most practical package is geometry.

Basic format:

\usepackage[top=distance,left=distance,bottom=distance,right=distance]{geometry}

The following example sets the top margin to 3 cm, left 3 cm, bottom 3 cm, and right 2.5 cm.

\documentclass[a4paper,12pt]{article}
\usepackage[top=3cm,left=3cm,bottom=3cm,right=2.5cm]{geometry}
\begin{document}
I am setting page margins in LaTeX.
\end{document}

[

Positive margin example
Positive margin example
](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRDDPdxDlirVDLOytIeGeGbuaBnbUBAwiPhobv6Nwra0CJMuD1KVp4ATULdzK0sANEuLr275Rp4lm6EHnpEc9_aG10u4xd20A_ZS7j5upm4EKVEVjvmATNCmlAJAuy4_3I3qLrueFZneo/s1249/margin1.png)

You do not have to specify every side. For example, this sets only the top and left margins:

\documentclass[a4paper,12pt]{article}
\usepackage[top=3cm,left=3cm]{geometry}
\begin{document}
I am setting page margins in LaTeX.
\end{document}

If all margins should be the same, use the shorthand margin option.

\documentclass[a4paper,12pt]{article}
\usepackage[margin=3cm]{geometry}

The geometry package also allows a margin of 0cm or even a negative value.

\documentclass{article}
\usepackage[top=0cm,left=3cm,bottom=3cm,right=-3cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\end{document}

With that setup, the text can start exactly at the top edge and even extend past the right boundary.

[

Zero and negative margin example
Zero and negative margin example
](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL0yFi8nJZ_OTz5pc9vppGWTtLboB-xiJn_yfnQSdodNUJ_aUbSpu8t9C1tpMknWxbcoUY6lLBe0R7bAIB-0AAyz9A12FsNARIsCoRfRn5p_cR_HgiatMgk8ZD_eQYe473ysycbRa_XfA/s1237/margin2.png)

This kind of setup is usually reserved for special layouts, not ordinary documents.

You can also change the margins in the middle of a document. For example, suppose page one uses 3 cm margins on all sides, but page two needs:

  • top: 4 cm
  • left: 6 cm
  • bottom: 4 cm
  • right: 5 cm

Use \newgeometry for that page.

\newgeometry{top=4cm,left=6cm,bottom=4cm,right=5cm}

[

Different margins on another page
Different margins on another page
](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEintxcMpA_EZX5WpxunUinfBhrfXae6LJ4V4yj3Mxk2BcAQGWtNKTW5wanwaJwixgejX0aYFrlPexl3MX5zBt5BYiRQmgugeEQ87cVmfwoDP90CdjRyJhGo9QFwyz643UXTWGjBo5qE6Wg/s708/margin3.png)

To return to the original margin settings from the preamble, use:

\restoregeometry

This command is usually placed at the beginning of the next page. If needed, add \newpage to force a page break.

In most documents, page margins only need to be set once. But for special pages containing large images, tables, or full-page graphics, it is useful to temporarily redefine the margins and then restore them.

With the geometry package, page margin control in LaTeX\LaTeX becomes simple and flexible.

Related Content