The
preamble of a LaTeX document is where the document is document type is defined. It is also the location where
packages are loaded. It can be thought of as the "setup" section of the document. The preamble consists of
everything "above" the \begin{document} line.
Comments (Optional but Useful)
To add notes for yourself or other editors in a LaTeX document, use
comments. Insert a percent symbol (
%), and everything after the symbol—
in that line—will be ignored by LaTeX. Comments can add a lot of clarity to a LaTeX document. They are used in some of the examples in this guide.
Document Class
Use the
\documentclass command to tell LaTeX what kind of document you are creating. There are several classes available, but here are some of the most common:
• article - for articles intended for publication in journals, academic research papers, etc.
• proc - based on the article class, it is for paper intended for conference proceedings.
• report - for longer documents containing multiple chapters, or for short books or theses.
• book - for actual books. This class is often used to write textbooks
• letter - for correspondence ("snailmail").
Setting Font Size in Document Class
The default font size in LaTeX is 10 points. If you want to change it, do so in square brackets in the
\documentclass command:
\documentclass[11pt]{article} % Setting font size to 11pts
Packages
Packages in LaTeX are macros, which are loaded in the preamble. The simple \usepackage command is all that's needed to make the features of a package available in your document.
Enabling three packages in a LaTeX document:
\usepackage{graphicx} % Required for inserting images
\usepackage{geometry} % For paper size, margins
\usepackage{hyperref} % Enables hyperlinks
Some Useful Packages
• amsmath - Optional, but very useful for mathematical equations.
• bpchem - Allows chemical formulas to be used.
• graphicx - Enables the use of images in the document.
• geometry - Needed for correcting paper size and setting margins.
• hyperref - Needed for hyperlinks
Setting Paper Size and Margins
The default paper size in LaTeX is the widely-used European A4 standard, which is 8.3 x 11.7 inches (210 x 297 mm). If you are creating a document to print on North American letter size (8.5 x 11 inches), you must set this in the preamble. The geometry package is needed, along with a short command in the preamble.
Let's set the paper size to US standard and margins to 1 inch:
\usepackage{geometry} % For paper size, margins
\geometry{letterpaper, margin=1in}
Setting Paragraph Spacing and/or First-Line Indentation (Optional)
By default in LaTeX, there's no blank line between paragraphs, and the first line of each paragraph is indented. If you need to change either or both of these, it can be done in the preamble with the \setlength command:
\setlength{\parindent}{0pt} % First-line indent is 0 points
\setlength{\parskip}{11pt} % Paragraph spacing is 11 points
Note: The above example uses points (
pt) as the unit of measure. A point is approximately 1/72 of an inch. You can also use inches (
in), centimeters (
cm), millimeters (
mm), ex's (
ex - the width of a lower-case
x in the current font), or em's (
em - the width of an uppercase
M in the current font).