Spacing in math mode in LaTeX (quad, thin space)
Math mode ignores the spaces you type. Add space with \, (thin), \: (medium), \; (thick), \quad (1 em) or \qquad (2 em); \! removes a thin space.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{amsmath}The spacing commands
One em is roughly the font size, about 10 pt in a 10 pt font. \, is 3/18 em wide, \: 4/18 em and \; 5/18 em. \ (a backslash and a space) is the space between two words, \quad is 1 em and \qquad 2 em. \! moves back by 3/18 em.
\[
a b \qquad a\,b \qquad a\:b \qquad a\;b \qquad a\ b \qquad a\quad b \qquad a\!b
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Where a thin space or a quad belongs
\, goes in front of a differential, between a number and its unit and after a root sign that is followed by a variable. \quad separates a formula from a condition, or two formulas in one line.
\[
\int_0^1 f(x)\,dx
\qquad
3\,\mathrm{m}
\qquad
\sqrt{2}\,x
\qquad
x = 1 \quad\text{and}\quad y = 2
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Remove space
\! closes a gap, for example the space LaTeX sets between a letter and \left(, or the visible gap between an exponent and the slash after it.
\[
\Gamma\left(\frac{1}{2}\right)
\qquad
\Gamma\!\left(\frac{1}{2}\right)
\qquad
x^2/2
\qquad
x^2\!/2
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Invisible placeholders
\phantom{...} takes up the space of its argument without printing it. In a matrix, \phantom{-} in front of the positive numbers makes the digits line up with those that have a minus sign. \hphantom keeps only the width, \vphantom only the height.
\[
\begin{pmatrix}
-1 & \phantom{-}2 \\
\phantom{-}3 & -4
\end{pmatrix}
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Give a symbol the spacing of an operator
LaTeX chooses the space around a symbol by its class. \mathbin{...} turns its argument into a binary operator with a medium space on both sides, \mathrel{...} into a relation with a thick space on both sides.
\[
a \triangle b
\qquad
a \mathbin{\triangle} b
\qquad
a \mathrel{\triangle} b
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Pitfalls
- An empty line inside a formula is not a space. It ends the paragraph and stops with Missing $ inserted.
- For space between words and paragraphs outside formulas see Horizontal and vertical space in LaTeX.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
amsmath - How-to Text in math mode in LaTeX
- How-to Integrals in LaTeX
- How-to Horizontal and vertical space in LaTeX
- How-to Non-breaking space in LaTeX