LaTeX error · Lengths and numbers

Illegal unit of measure (pt inserted)

Quick answer

Every length in LaTeX needs a unit. When TeX reads a number where it expects a length, such as \vspace{2} or width=5 in \includegraphics, it finds no unit after it and stops with this error, then assumes pt. Add a unit: \vspace{2cm}, width=5cm or a relative length like 0.8\textwidth. The units TeX knows are pt, pc, in, bp, cm, mm, dd, cc, sp, em and ex.

The error in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \relax 
l.4 \vspace{2}

Why it happens

  • A number with no unit in a length argument: \vspace{2}, \hspace{1}, \setlength{\parindent}{0}.
  • An unsupported unit such as px or %, or a misspelled unit like 2 mn.
  • A [ at the start of the line after \\: LaTeX reads \\[...] as an optional spacing, so \\ [1, 2] is taken as a length 1, with a bad unit.
  • A key such as width= or height= in \includegraphics or TikZ given a bare number.

How to fix it

Add the unit to the length. Absolute units (cm, mm, in, pt) are fine for fixed space; relative ones (em, ex, \textwidth, \linewidth) scale with the font or the page.

Even zero needs a unit: write 0pt (or \z@ in package code), not 0.

Broken: reproduces the error

\documentclass{article}
\begin{document}
First paragraph.
\vspace{2}
Second paragraph.
\end{document}

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

\documentclass{article}
\begin{document}
First paragraph.
\vspace{2cm}
Second paragraph.
\end{document}

Related errors

Frequently Asked Questions

What units can I use for lengths in LaTeX?

pt (point), pc (pica), in, bp (big point), cm, mm, dd, cc and sp are absolute; em and ex depend on the current font. You can also scale an existing length, as in 0.5\textwidth or 2\baselineskip.

Why does LaTeX say "pt inserted"?

After reporting the error TeX recovers by pretending you wrote pt after the number. If you press on, the document compiles with a length in points, which is rarely what you meant, so fix the unit rather than ignore it.

Can I use pixels or percent in LaTeX?

No. TeX has no px or % unit. For a fraction of the page use 0.5\textwidth or 0.5\linewidth; for an image size in pixels pick a physical width instead, such as width=6cm.

Why do I get this error after \\ in a table or address?

A line break \\ takes an optional length in square brackets. If the next line starts with [, LaTeX reads it as that length and fails on the content. Write \\ {}[1, 2] or \\ \relax [1, 2].

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →