Understanding Spacing in LaTeX
One of the first things beginners notice about LaTeX is that it treats white space differently than word processors like Microsoft Word. In LaTeX, multiple spaces in your source code are treated as a single space. Similarly, a single line break in your code is also treated as a single space.
To control how your text is laid out on the page, you need to use specific commands for line breaks, paragraph breaks, and spacing. This guide will teach you how to master the "flow" of your document.
1. Line Breaks vs. Paragraph Breaks
In LaTeX, there is a fundamental difference between moving to a new line and starting a new paragraph.
Starting a New Paragraph
To start a new paragraph, the best practice is to leave a blank line in your source code.
This is my first paragraph. I am explaining a very important concept.
This is my second paragraph. By leaving a blank line above, LaTeX
automatically handles the indentation or spacing between these blocks.Alternatively, you can use the \par command, which does the exact same thing as a blank line.
Forced Line Breaks
Sometimes you want to end a line without starting a new paragraph (for example, in a poem or an address). To do this, use the double backslash \\ or the \newline command.
123 LaTeX Lane \\
Typeset City, TX 77001 \\
USANote: Using
\\too frequently in standard prose is a common beginner mistake. It breaks the "justification" of the paragraph and can lead to ugly layout issues. Only use it when a physical line break is required by the content.
2. Adjusting Line Spacing (Leading)
In academic writing, you are often required to use "1.5 spacing" or "double spacing." While you could try to change this manually, the most reliable method is using the setspace package.
Using the setspace Package
To change the spacing of your entire document, add the package to your preamble and use one of the global commands.
\documentclass{article}
% Load the package
\usepackage{setspace}
% Set global spacing
\onehalfspacing % Use \doublespacing for double spacing
\begin{document}
This entire document will now have 1.5 line spacing, which is
excellent for readability and marking up drafts.
\end{document}Changing Spacing for Specific Sections
If you only want a specific part of your document (like a long quote) to be single-spaced while the rest is double-spaced, use the environments provided by the package:
\begin{doublespacing}
This paragraph is double-spaced to meet university requirements.
\end{doublespacing}
\begin{singlespace}
This part is single-spaced, perhaps because it is a block
quotation or a technical note.
\end{singlespace}3. Horizontal and Vertical Spacing
Sometimes you need to add a specific amount of "breathing room" between words or paragraphs.
Horizontal Space (\hspace)
The \hspace{length} command adds a fixed amount of horizontal space. You can use units like cm, mm, in, or pt.
Here is some text. \hspace{2cm} Here is text 2cm to the right.Vertical Space (\vspace)
The \vspace{length} command adds space between paragraphs.
This is the top paragraph.
\vspace{1cm}
This paragraph appears 1cm below the previous one.Warning: If you use
\vspaceat the very top or very bottom of a page, LaTeX may ignore it to keep the margins consistent. To "force" the space, use the starred version:\vspace*{2cm}.
4. Flexible Spacing with \hfill and \vfill
One of the most powerful features in LaTeX is "rubber lengths." These are spaces that stretch to fill all available room.
\hfill (Horizontal Fill)
Use \hfill to push text to the far edges of a line. This is commonly used for headers or signatures.
\noindent Left Side Text \hfill Right Side Text\vfill (Vertical Fill)
Use \vfill to push text to the bottom of a page. This is perfect for title pages.
\begin{titlepage}
\centering
{\huge My Great Thesis}
\vfill
A report submitted for the degree of Bachelor of Science \\
August 2023
\end{titlepage}5. Common Pitfalls and Best Practices
To keep your LaTeX code clean and your document professional, keep these tips in mind:
- Don't use
\\to create vertical gaps: Beginners often use\\ \\ \\to add space between paragraphs. This is bad practice and creates "Underfull \hbox" warnings. Instead, use\vspace{length}or let LaTeX handle paragraph spacing automatically. - Let LaTeX handle the indent: By default, LaTeX indents the first line of paragraphs (except the first one in a section). If you want to change this globally, don't manually add spaces. Use
\setlength{\parindent}{0pt}in your preamble. - The "One Space" Rule: Remember that LaTeX ignores extra spaces.
Word Wordbecomes "Word Word".- This is actually a feature! It allows you to format your code cleanly without affecting the final PDF output.
- Preventing Line Breaks: If you have two words that should never be separated across two lines (like "Fig. 1"), use a tilde
~instead of a space. This is called a "non-breaking space."Please refer to Figure~5 for the results.
Summary Table
| Goal | Command | Best Use Case |
|---|---|---|
| New Paragraph | Blank Line | Standard writing |
| New Line | \\ | Tables, Poetry, Addresses |
| 1.5 Spacing | \onehalfspacing | Academic papers (requires setspace) |
| Fixed Horiz. Space | \hspace{1cm} | Indenting specific elements |
| Fixed Vert. Space | \vspace{10pt} | Adding gaps between custom blocks |
| Push to Right | \hfill | Aligning dates or signatures |
| Push to Bottom | \vfill | Title pages |
