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.

aba ba ba  ba baba ⁣ba b \qquad a\,b \qquad a\:b \qquad a\;b \qquad a\ b \qquad a\quad b \qquad a\!b

Open this formula in the editor

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.

∫01f(x) dx3 m2 xx=1andy=2\int_0^1 f(x)\,dx \qquad 3\,\mathrm{m} \qquad \sqrt{2}\,x \qquad x = 1 \quad\text{and}\quad y = 2

Open this formula in the editor

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.

Γ(12)Γ ⁣(12)x2/2x2 ⁣/2\Gamma\left(\frac{1}{2}\right) \qquad \Gamma\!\left(\frac{1}{2}\right) \qquad x^2/2 \qquad x^2\!/2

Open this formula in the editor

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.

(−1−2−3−4)\begin{pmatrix} -1 & \phantom{-}2 \\ \phantom{-}3 & -4 \end{pmatrix}

Open this formula in the editor

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.

a△ba△ba△ba \triangle b \qquad a \mathbin{\triangle} b \qquad a \mathrel{\triangle} b

Open this formula in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages