Typevia
Text Formatting

Understanding the LaTeX Spacing Philosophy

One of the first things new LaTeX users notice is that the output doesn't always look like the input. If you type five spaces between two words in your editor, LaTeX will collapse them into a single space in the final PDF.

This is intentional. LaTeX follows a "logical design" philosophy: you provide the content and structure, and the engine handles the typography. LaTeX calculates the optimal spacing for readability based on professional typesetting standards. However, there are many situations where you need manual control over horizontal and vertical gaps. This guide will teach you how to master white space in LaTeX.

Note: In LaTeX, a single line break in your code is treated as a space. Two consecutive line breaks are treated as a "paragraph break."


Horizontal Spacing

Horizontal spacing refers to the gaps between words, characters, or elements on a single line.

Basic Horizontal Gaps

LaTeX provides several predefined commands for adding horizontal space:

  1. \quad: Creates a space equal to the current font size (usually the width of the letter 'M').
  2. \qquad: Creates a space twice as wide as \quad.
  3. \,: A very thin space (often used in math mode or between initials).
  4. \ (backslash followed by a space): Forces a standard word space.

Fixed Width Spacing: \hspace

If you need a specific measurement, use the \hspace{length} command. You can use units like centimeters (cm), millimeters (mm), inches (in), or points (pt).

This is a word.\hspace{2cm}This word is 2cm away.

You can also use negative values:
Over\hspace{-0.5cm}lap.

Elastic Spacing: \hfill

The \hfill (horizontal fill) command is one of the most powerful tools in LaTeX. It acts like a spring, pushing elements away from each other to fill the entire width of the line.

Left side \hfill Right side

% Using multiple hfills distributes space evenly
Start \hfill Middle \hfill End

Vertical Spacing

Vertical spacing controls the gaps between paragraphs, lines, and sections.

Predefined Vertical Skips

LaTeX includes three standard commands for adding vertical gaps that adapt to the document's font size:

  • \smallskip: Adds a small amount of space.
  • \medskip: Adds a medium amount of space.
  • \bigskip: Adds a large amount of space.

Custom Vertical Spacing: \vspace

Similar to horizontal spacing, you can define an exact vertical gap using \vspace{length}.

This is the end of a paragraph.

\vspace{1in}

This paragraph starts one inch below the previous one.

Warning: If you use \vspace at the very top or bottom of a page, LaTeX may ignore it to keep margins consistent. To force the space to appear, use the starred version: \vspace*{2cm}.

The Vertical Fill: \vfill

Just like \hfill, \vfill acts as a vertical spring. It is commonly used on title pages to push text to the very bottom of the page.

\begin{center}
    {\Huge My Great Thesis}
    
    \vfill
    
    A report by John Doe \\
    \today
\end{center}

Paragraph Management

By default, LaTeX indicates new paragraphs by indenting the first line rather than adding a vertical gap between them.

Indentation Control

If you want to force or prevent an indentation for a specific paragraph, use these commands:

  • \noindent: Placed at the start of a paragraph to remove the indent.
  • \indent: Forces an indent (though usually not necessary as it's the default).
\noindent This paragraph will not be indented, even if it is 
the start of a new section.

This paragraph will follow the standard indentation rules 
of the document class.

Changing Global Paragraph Style

If you prefer the modern style of "block paragraphs" (no indent, but a gap between paragraphs), the best practice is to use the parskip package in your preamble.

\documentclass{article}

% This package handles paragraph spacing automatically
\usepackage{parskip}

\begin{document}
Paragraphs will now have a gap between them and no indentation.
\end{document}

Special Spacing Characters

There are two special characters every LaTeX user should know regarding white space:

The Non-Breaking Space (~)

The tilde character ~ creates a normal space, but it prevents LaTeX from breaking the line at that point. This is essential for keeping titles and names together.

Professor~Smith % Prevents "Professor" and "Smith" being on different lines
Figure~\ref{fig:graph} % Keeps the word "Figure" with the number

The Forced New Line (\\)

While \par or a blank line starts a new logical paragraph, the double backslash \\ forces a line break without starting a new paragraph.

Line One \\
Line Two (still part of the same paragraph)

Best Practices and Common Pitfalls

  1. Don't use \\ to create vertical space. Beginners often type \\ \\ \\ to add gaps. This creates "Underfull \hbox" warnings and messy code. Use \vspace or \bigskip instead.
  2. Let LaTeX do the heavy lifting. Before adding manual spaces, ask yourself if a structural command (like \section or \item) would provide better, more consistent spacing.
  3. Use Relative Units. Instead of \hspace{12pt}, consider using \hspace{1em}. The unit em is relative to the current font size, meaning your spacing will stay proportional if you change the document font size later.
  4. Math Mode Spacing. Standard spaces are ignored in Math Mode. To add space inside an equation, use special commands like \, (thin), \: (medium), \; (thick), or \quad.
% Incorrect: $x + y = z$ (LaTeX ignores the spaces you type)
% Correct:
\[
f(x) = y \quad \text{if } x > 0
\]

By mastering these spacing techniques, you can move beyond the default LaTeX layout and create documents that are perfectly tailored to your visual requirements.