Tx · LaTeX & TikZ

How to Fix siunitx “Invalid numerical input”

Published By the 9to5Science editorial team

At a glance

  1. 1. Find the input

    Use the line number and table column in the error log to locate the value siunitx is trying to parse.

  2. 2. Check the format

    Make sure the entry contains a number written in a form siunitx recognizes, such as 12.5 or 1.2e3.

  3. 3. Separate text cells

    Use a regular text column or wrap text in an S column with a one-cell \multicolumn.

  4. 4. Set input conventions

    Configure input decimal markers if your data use commas, and keep units outside the parsed number.

The siunitx message “Invalid numerical input” means its number parser found content it could not interpret as a number. It most often appears in an S column, which aligns numerical values by their parts, or in a command such as \num{...}.

The fix is usually to locate the specific entry being parsed and either correct its number format or tell LaTeX that the cell is text. The examples below show how to do both.

What siunitx is trying to parse

An S column is not a general-purpose text column. siunitx examines each cell and parses its contents so it can align digits, decimal markers, and exponents. For example, 12.5 and 1.2e3 are recognizable numbers. A label such as n/a, a unit such as kg, or a dash is not a number, so it may trigger the error when placed directly in an S cell.

The same applies to \num{...}: its argument should be a number, not a complete phrase or a number with an unconfigured unit. The error log’s line number is a useful starting point, but the offending content may be in the table row immediately before or around that line.

Worked example: text in a numeric column

In this table, the first column contains descriptions and the second aligns numbers. The header and the text entry are explicitly set as ordinary centered cells rather than being parsed as numbers.

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{l S[table-format=2.2]}
\hline
Description & \multicolumn{1}{c}{Value} \\
\hline
First result & 12.50 \\
Second result & 3.75 \\
Not measured & \multicolumn{1}{c}{n/a} \\
\hline
\end{tabular}

\end{document}

S[table-format=2.2] tells siunitx to reserve space for a number with up to two digits before and two digits after the decimal marker. The table-format option controls the alignment layout; it does not make text a valid number. \multicolumn{1}{c}{n/a} overrides the S column for that one cell, so the text is not parsed as numerical input.

Common causes and fixes

A heading, dash, or note is in an S column

Use \multicolumn{1}{c}{...} for a text-only cell in an S column, as in the example. For a whole column of text, declare it as a normal l, c, or r column instead. Avoid putting units or explanatory words directly into a numeric cell; use a separate text column or format the number and unit separately.

The decimal marker differs from the input

By default, siunitx commonly expects a period as the decimal marker. If your data use decimal commas, configure the parser to accept commas. For example:

\sisetup{input-decimal-markers = {,}}

Then an entry such as 12,5 can be parsed as a number. Use the input setting for the values you type; output formatting is a separate concern. Check that the setting matches the actual data rather than changing punctuation blindly.

The entry includes unsupported material

In an S cell, enter the number alone: use 12.5 rather than 12.5 kg, about 12.5, or 12.5\%. Put associated text in another cell, or override the numeric column for that entry using \multicolumn. For a percent value, store the numeric part in the S cell and place the percent symbol in a separate column or add it in a way supported by your siunitx settings.

A \num argument contains more than a number

Write \num{1234.5} for number formatting, not \num{1234.5 kg}. If you need a unit, use siunitx’s quantity command, such as \qty{1234.5}{\kilogram}, with the appropriate unit definition available in your installed version. For older siunitx releases, consult that version’s manual because command names and interfaces can differ.

Check the input one cell at a time

If the message remains, temporarily simplify the reported row. Replace the suspicious entry with a plain number, then restore its content in smaller pieces. Also check for an accidental extra column separator (&), an unescaped special character, or a macro that expands to text inside the numeric cell. Those can make it appear that siunitx is rejecting a different value than the one you intended.

Valid numeric forms include ordinary decimals and scientific notation, such as 0.004 and 4e-3. Depending on the input and settings, siunitx also supports signs and uncertainty notation, for example 1.23(4). If a valid-looking entry still fails, check the package manual for the syntax supported by your installed siunitx version and any customized input options.

Common mistakes to avoid

  • Treating S as a text column: use l, c, or r for text, or override an individual S cell with \multicolumn.
  • Assuming table-format fixes invalid input: it reserves alignment space; it does not convert labels or units into numbers.
  • Mixing decimal conventions: configure input markers to match the data you type.
  • Putting units inside the number: keep the numerical value and unit separate, or use a quantity command supported by your version.
  • Changing several settings at once: first identify the offending cell, then make the smallest correction that resolves it.

References

  1. siunitx — A comprehensive (SI) units package, CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.