LaTeX error "Missing number, treated as zero": cause and fix
TeX expected a number or a length and found something else. It goes on with the value 0.
Why it happens
- A table row begins with
[directly after the\\of the row before. LaTeX reads[...]as the optional argument of\\, which sets extra space below the row. - A length argument is empty:
\vspace{},\hspace{},\rule{}{1pt}orwidth=without a value. - A word stands where a number belongs:
\setcounter{section}{two}or\hspace{big}. - The backslash of a new name is missing, as in
\newcommand{name}{...}. See Missing control sequence inserted.
How to fix it
- Put the bracketed cell in braces,
{[Knuth]}, so that the[no longer follows\\directly. - Give every length a number and a unit, for example
\vspace{1em}. - Write counter values as digits:
\setcounter{section}{2}. - If Illegal unit of measure (pt inserted) follows for the same line, both errors come from the same spot.
A document that produces the message
\documentclass{article}
\begin{document}
\begin{tabular}{ll}
Source & Pages \\
[Knuth] & 12 \\
\end{tabular}
\end{document}The corrected document
\documentclass{article}
\begin{document}
\begin{tabular}{ll}
Source & Pages \\
{[Knuth]} & 12 \\
\end{tabular}
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.