Document Structure

Learn how to structure a LaTeX document using the preamble, document class, and sections.

Every LaTeX document is divided into two main parts: the preamble and the body.

The Preamble

The preamble is everything that comes before \begin{document}. This is where you configure the document's global settings, load packages, and define custom commands.

\documentclass[12pt, a4paper]{article}
 
% This is the preamble
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
 
\title{My Document}
\author{John Doe}
\date{\today}
 
\begin{document}

Document Class

The very first line must be \documentclass{...}. Common classes are:

  • article: For short reports, papers, and essays.
  • report: For longer documents with chapters (e.g., small theses).
  • book: For actual books.
  • beamer: For presentations and slides.

The Body

The body of the document is enclosed between \begin{document} and \end{document}. Everything you write here will be printed on the page.

Sections and Subsections

You can organize your document into logical sections. LaTeX will automatically number them and format the headings.

\section{Introduction}
This is the first section.
 
\subsection{Background}
This is a subsection inside the introduction.
 
\subsubsection{Historical Context}
And a sub-subsection.

If you don't want a section to be numbered, add an asterisk (*):

\section*{Conclusion}
This section will not have a number, but will still be formatted as a heading.
Table of Contents

Because you used logical sectioning commands, LaTeX can automatically generate a table of contents for you. Just type \tableofcontents right after \begin{document}!