Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 38 ยท Getting Started

Document Classes and the Preamble

Learn how \documentclass and its options work, how article, report, book, letter and beamer differ, and how to load packages and set metadata in the preamble.

Every LaTeX file starts with a line that says what kind of document you are writing: \documentclass{...}. This single choice sets the paper size, the base font size, how headings look and number, and which commands exist. After it comes the preamble, the setup area where you load packages and define options before the text begins.

Understanding these two parts means you can open any LaTeX file, including a journal template with 200 lines of setup, and know what you are looking at.

The \documentclass command

LATEX
\documentclass[options]{class}

It must be the very first command in the file. The class is required; the options are an optional comma-separated list.

The standard classes

Class Meant for Top heading level Notes
article Papers, short reports, notes, homework \section No chapters; a title block sits on the first page
report Longer reports, theses, manuals \chapter Chapters start on new pages; has a title page option
book Books \chapter Two-sided by default; front, main and back matter
letter Letters n/a Uses a letter environment, \opening and \closing
beamer Slides \section, frames Covered in chapter 8
memoir Flexible books and theses \chapter A powerful replacement for book and report
standalone A single figure or formula as a tight-fitting PDF n/a Handy for graphics

Beyond these, publishers provide their own classes: IEEEtran, acmart, revtex4, elsarticle, llncs. They are used exactly the same way, and the journal's template tells you which options to pass.

flowchart TD
  Q{"What are you writing?"} -->|"Short paper or notes"| A["article"]
  Q -->|"Thesis or long report"| R["report or memoir"]
  Q -->|"A whole book"| B["book or memoir"]
  Q -->|"Slides"| S["beamer"]
  Q -->|"Journal submission"| J["The journal's own class"]

When a journal or university provides a class, always use it.

Class options

Options change the defaults. The most common ones apply to the standard classes.

Option Effect
10pt, 11pt, 12pt Base font size (default 10pt)
a4paper, letterpaper, a5paper Paper size
oneside, twoside Same margins on all pages, or mirrored for printing
onecolumn, twocolumn Number of columns
titlepage, notitlepage Whether the title gets its own page
landscape Rotate the page
draft Marks overfull lines with a black box and skips images
fleqn, leqno Flush-left or left-numbered equations

Combine them with commas and no spaces needed:

LATEX
\documentclass[12pt,a4paper,twoside]{report}

Use the stand-in below to build a \documentclass line. It only assembles text; the compiler does the real work.

Build a \documentclass line (stand-in)

The preamble

Everything between \documentclass and \begin{document} is the preamble. It has three jobs.

1. Load packages

A package adds features. You load one with \usepackage.

LATEX
\usepackage{amsmath}                 % advanced math
\usepackage{graphicx}                % include images
\usepackage[margin=2.5cm]{geometry}  % page margins, with an option
\usepackage{amsmath,amssymb}         % several at once

Packages come from the distribution; there are thousands. The packages chapter covers the ones you will use most. Two habits save trouble: load hyperref near the end of the preamble (it changes other packages' behavior), and never load the same package twice with different options.

2. Encoding and fonts (pdfLaTeX)

Modern LaTeX reads UTF-8 by default, so accented letters in the source work. For good accented output and copy-and-paste from the PDF, older setups add:

LATEX
\usepackage[T1]{fontenc}   % proper font encoding, better hyphenation of accents
\usepackage{lmodern}       % scalable Latin Modern fonts

With XeLaTeX or LuaLaTeX you would load fontspec instead.

3. Metadata and your own settings

Title information is declared in the preamble and printed later by \maketitle in the body.

LATEX
\title{Notes on Sorting}
\author{Ada Student \\ Example University}
\date{March 2026}     % \date{} prints no date; \today prints today's date

You can also tune layout there: \setlength{\parindent}{0pt} removes paragraph indentation, and \renewcommand{\baselinestretch}{1.2} changes line spacing.

A complete annotated skeleton

LATEX
\documentclass[11pt,a4paper]{article}

% ---------- packages ----------
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=2.5cm]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}      % loaded last or nearly last

% ---------- metadata ----------
\title{A Skeleton Document}
\author{Your Name}
\date{\today}

% ---------- document ----------
\begin{document}
\maketitle
\tableofcontents

\section{Introduction}
Text goes here.

\end{document}

Keep a file like this as your starting point for new projects.

Defining your own shortcuts

The preamble is also where you define commands you reuse. \newcommand creates one.

LATEX
\newcommand{\R}{\mathbb{R}}            % needs amssymb or amsfonts
\newcommand{\code}[1]{\texttt{#1}}     % one argument, referred to as #1

Now \code{main.tex} prints main.tex in a typewriter font, and if you later want code in a different style you change one line. Use \renewcommand to redefine an existing command, and remember that \newcommand refuses to overwrite one that exists, which protects you from accidents.

Reading a package's documentation

You do not need to memorise options. Every package has a PDF manual. From a terminal, run texdoc geometry (replace with the package name) and your distribution opens it. This habit, more than anything, separates comfortable LaTeX users from frustrated ones.

Common mistakes

  • Putting text before \begin{document}: the engine reports "Missing \begin{document}".
  • Typing \usepackage inside the document body: it must be in the preamble.
  • Forgetting a comma between two package names, or adding a space before a option: [a4paper, 12pt] is fine but a missing comma is not.
  • Using \documentclass twice or not first, for example after a comment-less blank line of text.
  • Loading a package that is not installed: the log says "File `name.sty' not found". Install it with the distribution's package manager.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which class would you choose for a thesis with chapters?

    report, book and memoir provide \chapter; article does not.
  2. 2. Where does the preamble end?

    The preamble is everything between \documentclass and \begin{document}.
  3. 3. What does \usepackage[margin=2.5cm]{geometry} do?

    The part in square brackets is a package option; geometry uses it to set margins.
  4. 4. How do you get the manual of the package geometry from the command line?

    texdoc finds and opens the documentation installed with your distribution.

Summary

  • \documentclass[options]{class} must come first and sets the document type.
  • article, report, book, letter, beamer and memoir are common; journals supply their own.
  • Options such as 12pt, a4paper and twocolumn change defaults.
  • The preamble loads packages with \usepackage, declares title, author and date, and defines your own commands.
  • Use texdoc package to read the real documentation.

Next: Text Formatting: Bold, Italic and Emphasis