Spacing in LaTeX: Horizontal, Vertical and Math Mode Spacing

Quick answer

  • Small fixed spaces: \, thin, \: medium, \; thick, \! negative thin, \quad 1em, \qquad 2em.
  • Exact horizontal space: \hspace{1cm}; \hfill fills the line.
  • Vertical space: \vspace{1em}, \\[1em] after a line break, \smallskip \medskip \bigskip; \vspace*{} at the top of a page.
  • Paragraphs and lines: \setlength{\parskip}{0.5em}, \linespread{1.3} or setspace with \onehalfspacing / \doublespacing.
\documentclass{article}
\usepackage{setspace}
\onehalfspacing                      % line spacing
\setlength{\parskip}{0.5em}          % space between paragraphs

\begin{document}
Left\hspace{2cm}right \quad a\qquad b \hfill end of line

\bigskip
After a big skip.\\[1em]
A new line 1em further down.

\vspace{1cm}
Math: $a\,b \quad a\:b \quad a\;b \quad a\!b$
\end{document}

LaTeX sets almost all spacing for you: spaces between words, between sentences, around operators in math, between paragraphs and above headings. Most of the time the right move is to leave it alone. When you do need to change it, there is a specific command for each direction and mode. This guide covers horizontal space in text, vertical space between paragraphs and blocks, the spacing commands for math mode (with their exact widths in mu), line spacing and paragraph spacing, and the errors that spacing commands produce.

Horizontal Spacing

Spaces in the source are collapsed: one space, ten spaces and a single line break all produce one interword space, and spaces at the start of a line are ignored. To get more room, use one of the spacing commands:

CommandWidthUse
\, or \thinspace1/6 emBetween a number and a unit, initials: 5\,kg
\enspace1/2 emA clear gap, e.g. before an item label
\quad1 emSeparating items on one line
\qquad2 emA wider separation
\hspace{1cm}Exactly 1cmAny fixed width; negative values pull back
\hspace*{1cm}Exactly 1cmSame, but kept at the start of a line
\hfillAll available spacePush text to the right margin, spread items
~One interword spaceA space the line cannot break at: Figure~1
\ (backslash space)One interword spaceA normal space after a command or abbreviation
\phantom{text}Width of textInvisible placeholder for alignment
\documentclass{article}
\begin{document}

Name:\hspace{3cm}Date:\hspace{2cm}   % gaps for a form

Left \hfill Right                     % right-aligned text on the same line

Left \hfill Middle \hfill Right       % three evenly spread items

Chapter 1 \dotfill 7                  % dotted leader, as in a contents line

\hspace*{2em}Indented by hand at the start of the line.

5\,kg, 20\,\%, D.\,E. Knuth, Figure~3, Mr.~Smith

\end{document}

Two details catch people out. First, \hspace at the very start of a line is discarded like any other space there; use \hspace* to keep it. Second, a command name eats the space after it, so \LaTeX is prints “LaTeXis”. Write \LaTeX{} is or \LaTeX\ is.

Space after a period

LaTeX puts a slightly wider space after a sentence-ending period than between words. It guesses that a period after a lowercase letter ends a sentence and one after a capital does not. Correct the guess where it is wrong: e.g.\ this or e.g.~this after an abbreviation, and PhD\@. Then when a sentence ends with a capital. \frenchspacing in the preamble turns the wider space off altogether, which many style guides now prefer.

Vertical Spacing

Vertical space goes between paragraphs. \vspace adds an exact amount; the three skip commands add standard amounts that stretch slightly so pages still fill well:

CommandAmount
\smallskip3pt plus 1pt minus 1pt
\medskip6pt plus 2pt minus 2pt
\bigskip12pt plus 4pt minus 4pt
\vspace{1cm}Exactly 1cm (any length, also negative)
\vspace*{1cm}Same, but kept at the top of a page
\\[1em]Line break plus 1em of extra space
\vfillAll remaining space on the page
\documentclass{article}
\begin{document}

\vspace*{3cm}                      % kept even at the top of the page
\begin{center}
  {\Large A Title Page}\\[2em]
  Ada Lovelace\\[0.5em]
  \today
\end{center}

\vfill                             % push the rest to the bottom
Submitted in partial fulfilment of the requirements.

\newpage
First paragraph.

\medskip
Second paragraph, after a medium skip.

\vspace{1.5\baselineskip}
Third paragraph, one and a half blank lines further down.

\end{document}

Use units that scale with the font for spacing in running text: em (the width of an M), ex (the height of an x) or \baselineskip (one line). Fixed units such as cm and pt suit title pages and forms. Do not use repeated \\ or empty lines to make vertical space: they produce Underfull \hbox warnings or the error There's no line here to end.

Spacing in Math Mode

In math mode, spaces in the source are ignored completely; TeX decides the spacing from what each symbol is (operator, relation, punctuation). To adjust it, use the math spacing commands. Their widths are given in mu (math units): 1mu is 1/18 of an em in the current math font, so the spaces scale correctly in subscripts.

CommandLong form (amsmath)WidthExample use
\!\negthinspace−3muPull symbols together: \int\!\!\int
\,\thinspace3muBefore dx in an integral: f(x)\,dx
\: (also \>)\medspace4mu plus 2mu minus 4muThe space around + and −
\;\thickspace5mu plus 5muThe space around =; before a condition
\ (backslash space)—one interword space (about 6mu)A word-sized gap
\quad—1em = 18muBetween an equation and a condition
\qquad—2em = 36muBetween two equations on one line
\mspace{5mu}—Any amount in muFine-tuning (amsmath)
\hspace{1em}—Any text lengthWorks in math too
\documentclass{article}
\usepackage{amsmath}
\begin{document}

% The four small spaces, from negative to thick
\[ ab \quad a\!b \quad a\,b \quad a\:b \quad a\;b \]

% Typical uses
\[ \int_0^1 f(x)\,dx \qquad \int\!\!\int_D g\,dA \]
\[ f(x) = x^2, \quad x > 0 \qquad \text{for all } y \]
\[ \{\, x \mid x > 0 \,\} \qquad \sqrt{2}\,x \qquad \sin x\,\cos x \]
\[ a = b \qquad\text{and}\qquad c = d \]

\end{document}

For words inside math, use \text{ and } from amsmath, with the spaces inside the braces; they are kept because \text switches back to text mode. Spacing around relations and operators that looks wrong is usually a sign of the wrong symbol: < instead of \langle (see brackets), or | instead of \mid in set notation. For operator names, \sin and \DeclareMathOperator add the correct space automatically (see math functions).

Line Spacing

Line spacing (the distance between baselines, \baselineskip) is set by the font size. To change it for the whole document, the setspace package is the reliable way: it scales the body text but keeps footnotes, captions, and floats such as tables single-spaced, as most thesis rules require.

\documentclass[12pt]{article}
\usepackage{setspace}
\onehalfspacing          % or \doublespacing, or \setstretch{1.3}

\begin{document}
This paragraph is one-and-a-half spaced.\footnote{The footnote stays single-spaced.}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

\begin{singlespace}
A single-spaced block quotation or code listing, inside a
one-and-a-half spaced document.
\end{singlespace}

\begin{spacing}{2}
A double-spaced passage.
\end{spacing}
\end{document}

Without a package, \linespread{1.3} in the preamble multiplies the baseline skip everywhere, including footnotes and tables. The factor is not the “line spacing” a word processor means: because the default baseline skip is already 1.2 times the font size, one-and-a-half spacing is about \linespread{1.25} and double spacing about \linespread{1.65}. In the document body, \linespread only takes effect after \selectfont. For the font sizes behind \baselineskip, see LaTeX font size.

Inside tables, the row height is controlled by \renewcommand{\arraystretch}{1.3} and the column gap by \setlength{\tabcolsep}{8pt}; the tables guide has more on both.

Paragraph Spacing

A blank line in the source starts a new paragraph. By default LaTeX marks new paragraphs with an indent (\parindent) and no extra space (\parskip is 0pt plus 1pt). To switch to the block style, with space between paragraphs and no indent, the parskip package is the clean option:

\documentclass{article}
\usepackage{parskip}     % no indent, half a line of space between paragraphs

\begin{document}
First paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Second paragraph, separated by space instead of an indent.

\noindent This paragraph would not be indented in the default style either.
\end{document}

Setting the lengths by hand does the same with exact values, but the space then also appears inside lists, the table of contents and some environments, which parskip corrects:

\documentclass{article}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}

\begin{document}
First paragraph.

Second paragraph, 6pt lower.
\end{document}

Spacing inside lists is a separate setting; the enumitem package's nosep and itemsep options are covered in lists, and space around headings in sections.

Common Errors and Fixes

Message or symptomCauseFix
Missing number, treated as zeroA length was expected but not given: \vspace{}, \hspace{big}, or a line starting with [ right after \\Give a length (\vspace{1em}); after \\ write \\ \relax or {[}
Illegal unit of measure (pt inserted)A number without a unit: \vspace{2}Add the unit: \vspace{2em}, 2cm, 12pt
\vspace at the top of a page has no effectVertical space is discarded at page breaksUse \vspace*{...}
\hspace at the start of a line has no effectHorizontal space is discarded at line breaksUse \hspace*{...}
LaTeX Error: There's no line here to end\\ after a blank line or at the start of a paragraph, used for vertical spaceUse \vspace or \bigskip between paragraphs
Underfull \hbox (badness 10000) in paragraph\\ at the end of a paragraph, or \\\\ to make a blank lineEnd paragraphs with a blank line; add space with \\[1em] or \vspace
Words run together after a command (“LaTeXis”)A command name swallows the following space\LaTeX{} is or \LaTeX\ is
Spaces typed in math disappearMath mode ignores source spaces\,, \quad or \text{ word }

The bracket case is the least obvious. LaTeX reads the line below as the optional argument of \\, the extra space after the break, and [a, b] is not a length:

\documentclass{article}
\begin{document}
% Wrong: "\\" followed by "[a, b]" on the next line gives
% "Missing number, treated as zero"
% The interval is\\
% [a, b].

The interval is\\ \relax
[a, b].
\end{document}

Frequently Asked Questions

How do I add a space in LaTeX?

Ordinary spaces in the source become one interword space, however many you type. For more, use \quad (1em) or \qquad (2em), \hspace{1cm} for an exact width, \, for a thin space, or ~ for a space the line cannot break at. In math mode spaces in the source are ignored entirely, so use \, \: \; \quad or \text{ } there.

How do I add vertical space in LaTeX?

Use \vspace{1cm} between paragraphs, \smallskip, \medskip or \bigskip for standard amounts (3pt, 6pt and 12pt), or \\[1em] to add space after a line break. \vspace is dropped at the top of a page; use \vspace* there. \vfill pushes the content apart to fill the page.

What do \, \: \; and \! do in LaTeX?

They are the math spaces. \, is a thin space (3mu), \: a medium space (4mu), \; a thick space (5mu) and \! a negative thin space (-3mu) that pulls symbols together. One mu is 1/18 of an em, so \quad is 18mu and \qquad 36mu. \, also works in text, for example between a number and its unit.

How do I set double spacing or 1.5 line spacing in LaTeX?

Load the setspace package and write \doublespacing or \onehalfspacing in the preamble, or \setstretch{1.5} for a custom factor. setspace keeps footnotes, captions and tables single-spaced. \linespread{1.5} also works but scales everything, and it gives noticeably more than one-and-a-half spacing, close to double.

How do I add space between paragraphs instead of indenting them?

Load the parskip package: \usepackage{parskip}. It sets the paragraph indent to zero and adds about half a line of space between paragraphs, while keeping lists and the table of contents tidy. Setting \setlength{\parskip}{1em} and \setlength{\parindent}{0pt} by hand also works but adds the space in places you may not want.

Why does LaTeX say “Missing number, treated as zero”?

A command that expects a length got something else: an empty \vspace{}, a word instead of a length, or a line that starts with [ right after \\, which LaTeX reads as the optional spacing argument of \\. Give a real length such as \vspace{1em}, and write \\ \relax or {[} when the next line starts with a bracket. A number without a unit gives “Illegal unit of measure (pt inserted)” instead.

Next Steps

Free LaTeX Tools

Fix spacing problems faster with AI

Octree's AI editor explains “Missing number” and underfull box warnings, sets up thesis line spacing for you, and compiles your document in seconds.

Try Octree Free →