BudiBadu Logo
Samplebadu

LaTeX by Example: Document Class

LaTeX2e

The `\documentclass` command is the foundation of any LaTeX document. This sample explains how to choose the right class and set global options.

Code

% Basic article class with 12pt font
\documentclass[12pt, a4paper]{article}

% Other common classes:
% \documentclass{report}  % For longer reports with chapters
% \documentclass{book}    % For books
% \documentclass{beamer}  % For presentations

\begin{document}
    Hello, World!
\end{document}

Explanation

Every LaTeX document starts with the \documentclass command. This command tells LaTeX what kind of document you are creating, which in turn determines the overall layout and available commands. The most common class is article, suitable for short papers, journal articles, and general reports. Other standard classes include report for longer documents containing chapters, and book for real books.

You can pass optional arguments to the document class in square brackets []. Common options include font size (e.g., 10pt, 11pt, 12pt), paper size (e.g., a4paper, letterpaper), and column layout (e.g., twocolumn). These global settings apply to the entire document unless overridden locally.

The content of your document is enclosed within the document environment, marked by \begin{document} and \end{document}. Everything before \begin{document} is called the preamble, where you load packages and define custom commands. Everything after \end{document} is ignored by the compiler.

Code Breakdown

2
\documentclass[12pt, a4paper]{article} sets the font size to 12 points and paper size to A4.
10
\begin{document} marks the start of the visible content.