Building Document Hierarchy

Introduction

Welcome to Document Structure and Layout, the second course in your LaTeX learning path! In the previous course, you built a solid foundation with basic documents, text formatting, and alignment. Now you are ready to take the next step: organizing your writing into well-structured, professional documents. In this first lesson, we will explore how to divide a document into sections, subsections, and subsubsections, giving your work a clear heading hierarchy with automatic numbering.

Why Documents Need Hierarchy

Think about any book, report, or article you have read. It is almost certainly broken into titled parts — chapters, sections, or numbered headings. Without this structure, even well-written content becomes a wall of text that is hard to navigate.

LaTeX was designed with this need in mind. Instead of manually typing heading numbers and formatting them by hand, LaTeX provides dedicated commands that handle both the visual formatting and the numbering for you. This means you can focus on your content while LaTeX keeps your headings consistent and correctly numbered, even as you add or rearrange parts of your document.

The `\section{}` Command

The highest everyday heading level in a standard LaTeX article is the section. You create one by placing the \section{} command in your document body, with the heading title as its argument. Here is a minimal example:

\documentclass{article}
\begin{document}

\section{Introduction}
This is the opening section of our document.

\section{Methods}
Here we describe the methods used.

\end{document}

When compiled, LaTeX produces two numbered headings, 1 Introduction and 2 Methods, each in a larger, bold font. Notice that you never typed the numbers yourself — LaTeX assigned them automatically in the order the sections appear.

Compiled output showing two automatically numbered section headings

Adding Subsections with `\subsection{}`

Inside a section, you will often want to break content into smaller topics. The \subsection{} command creates a second-level heading nested under the current section:

\section{Methods}

\subsection{Data Collection}
We gathered data from three sources.

\subsection{Analysis}
The data was processed using standard techniques.

In the compiled output, these headings appear as 2.1 Data Collection and 2.2 Analysis (assuming "Methods" is section 2). The numbering scheme uses a dot to show the parent-child relationship: the first number is the section, and the second is the subsection within it.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal