LaTeX by Example: Page Layout
Controlling margins and page orientation is essential. This example demonstrates how to use the `geometry` package to customize the page layout.
Code
\documentclass{article}
% The geometry package gives full control over page layout
\usepackage[
a4paper,
left=2.5cm,
right=2.5cm,
top=3cm,
bottom=3cm,
landscape % Optional: sets page to landscape orientation
]{geometry}
\begin{document}
This page has custom margins defined by the geometry package.
The text area is centered with 2.5cm side margins.
\end{document}Explanation
While LaTeX has sensible defaults for page margins (often quite large to optimize readability), you frequently need to customize them. The standard way to do this is by using the geometry package. It provides a flexible interface to specify margins, paper size, and orientation without needing to perform complex calculations or mess with low-level TeX dimensions.
You can load the package with options in the preamble. Common parameters include left, right, top, and bottom to set specific margin sizes. You can also specify margin=2cm to set all four margins at once. The a4paper or letterpaper options ensure the PDF output matches your physical paper size.
The geometry package also handles page orientation. Adding the landscape option rotates the page 90 degrees. This is particularly useful for wide tables or charts that don't fit on a standard portrait page. You can even switch between portrait and landscape within the same document using specific commands provided by the package.
Code Breakdown
\usepackage[...] {geometry} loads the package with the specified configuration.landscape changes the orientation. Remove this line for standard portrait mode.
