siunitx error: “invalid-number” Invalid numerical input 'e'

Well I've been working in some tables and for the number alignment I normally use the siunitxpackage since Mico helped me with this question.

But I've had in these new tables an error I don't understand how to solve.

siunitx error: "invalid-number" Invalid numerical input 'e'.
For immediate help type H <return>. \end{tabularx}


I found these questions about it: question 1 and question 2. Unfortunately it isn't the same case, and I haven't found clues leading me to the solution.

My MWE is:

\documentclass[fontsize=10pt,paper=letter,headings=small,bibliography=totoc,DIV=9,headsepline=true,titlepage=on]{scrartcl}
\usepackage[spanish,mexico]{babel}
\usepackage{xspace}
\usepackage{xkeyval}
\usepackage{array,multirow,multicol,rotating,tabularx,ragged2e,booktabs}
%\newcolumntype{Y}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
%\newcolumntype{C}{>{\centering\arraybackslash\hspace{0pt}}X}
\usepackage{rotating} % Paquete para rotar objetos flotantes
\usepackage{colortbl} % Paquete pata colorear tablas
\usepackage[per-mode=symbol]{siunitx} % Paquete para insertar unidades
\sisetup{
output-decimal-marker = {.},
group-minimum-digits = 4,
range-units = brackets,
list-final-separator = { \translate{and} },
list-pair-separator = { \translate{and} },
range-phrase = { \translate{to (numerical range)} },
}
\ExplSyntaxOn
\providetranslation [ to = Spanish ]
{ to~(numerical~range) } { a } % substitute the right word here
\ExplSyntaxOff

\begin{document}

\begin{table}[htbp]
\centering
\caption{Mercado de energía eléctrica en Norteamérica}
\label{tab:emna}
\begin{tabularx}{\linewidth}{@{}lYrYrYrYr @{}}
\toprule
País & Producción [\si{\giga\watt\hour}] & Fecha & Consumo [\si{\giga\watt\hour}] & Fecha & Exportaciones [\si{\giga\watt\hour}] & Fecha & Importaciones [\si{\giga\watt\hour}] & Fecha \\
\midrule
Canadá         &  612000 & 2007 &  530000 & 2006 & 50120 & 2007 & 19660   & 2007 \\
Estados Unidos & 4167000 & 2007 & 3892000 & 2007 & 20140 & 2007 & 51400   & 2007 \\
México         &  243300 & 2007 &  202000 & 2007 &  1278 & 2007 &   482.2 & 2007 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


I try to use S column-type in the middle and right columns but I can't because the error mentioned before. I tried using simply S column without success and later S[table-format=5.0] but that didn't work. What's wrong with my tables?

Update

Although both answers were very interesting and useful, I'm afraid my problem persists. I can't add to my tables columns type S and I need them.

Now I add a table that currently work with the same problem, in which I used the column type Y meanwhile but the result hasn't been satisfactory.

I guess one of the packages in my preamble is responsible, see if I can detect itbecause the MWE seems to work smoothly.

• If I take the code currently here, adjust to S columns and escape the column headers by adding brace groups then all is fine. Can you edit in a MWE that actually does show the issue, otherwise it will be impossible to solve. – Joseph Wright Aug 26 '15 at 6:11
• @JosephWright I work on it, for the moment the only option would be to place my full preamble, which would not be a MWE. So later (now I need to sleep a while), I'll try to see if I find a package that causes the error and update the MWE. Thank you. – Aradnix Aug 26 '15 at 7:44
• @Mico I tried to update the question because the error remains, instead of open a new one that later will be closed because is duplicated or simply considered as off-topic. I simply changed the table for the new one with the same error. The preamble is still the same than before. – Aradnix Aug 26 '15 at 7:45
• @Mico I apologize for the trouble I've generated. It's the 1st time I make a bounty and, from previous experience, I decided to do it this way instead of creating a new question. The reason was that it was never solved the problem as I have indicated. However, the 2 answers I received previously were very useful and I think that erasing is not a good idea. Finally are 2 very good suggestions that someone else could see and possibly use. In my opinion, the change was not radical in updating the question, all I did was change the table where a new issue that I asked the question again appeared. – Aradnix Aug 26 '15 at 20:42
• @Aradnix 'Don't use tabularx', or at least 'Don't expect siunitx columns to mess about with spacing'. They are designed to be as far as possible the size of the content. – Joseph Wright Aug 26 '15 at 21:13

(Re-wrote the answer after the OP changed the table in the MWE.)

The following solution lets you use the S column type for the four "GWh" columns and lets you use a tabularx environment (to assure that the width of the table is equal to \linewidth). The trick -- such as it is -- consists of using S for the numbers and C (a centered version of X) for the headers.

You'll observe that I've reorganized the table's header. Your original setup requires line-breaks for all four important header words -- Producción, Consumo, Exportaciones, and Importaciones. I think it's better to avoid (as much as possible) the hyphenation of such words. I left the square brackets around the GWh headers; however, they may not be needed.

(To simplify and streamline the preamble code, I've also removed all packages that don't appear to be essential to generating the table.)

\documentclass[fontsize=10pt,paper=letter,headings=small,bibliography=totoc,
\usepackage[spanish,mexico]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" column type
\newcommand\mc[1]{\multicolumn{2}{@{}C@{}}{#1}}  % shortcut macro

\usepackage{siunitx} % Paquete para insertar unidades
\sisetup{
per-mode = symbol,
output-decimal-marker = {.},
group-minimum-digits = 4,
range-units = brackets,
list-final-separator = { \translate{and} },
list-pair-separator = { \translate{and} },
range-phrase = { \translate{to (numerical range)} },
}
\ExplSyntaxOn
\providetranslation [ to = Spanish ]
{ to~(numerical~range) } { a } % substitute the right word here
\ExplSyntaxOff

\begin{document}

\begin{table}
\caption{Mercado de energía eléctrica en Norteamérica}
\label{tab:emna}
\begin{tabularx}{\linewidth}{@{} l
*{2}{S[table-format=7.0]r}
S[table-format=5.0]r
S[table-format=5.1]r @{}}
\toprule
País & \mc{Producción} & \mc{Consumo} & \mc{Exportaciones} & \mc{Importaciones} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
& [\si{\giga\watt\hour}] & Fecha & [\si{\giga\watt\hour}] & Fecha
& [\si{\giga\watt\hour}] & Fecha & [\si{\giga\watt\hour}] & Fecha \\
\midrule
Canadá         &  612000 & 2007 &  530000 & 2006 & 50120 & 2007 & 19660   & 2007 \\
Estados Unidos & 4167000 & 2007 & 3892000 & 2007 & 20140 & 2007 & 51400   & 2007 \\
México         &  243300 & 2007 &  202000 & 2007 &  1278 & 2007 &   482.2 & 2007 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


Addendum: Here's the same table, but without the reorganization of the header material. The code is the same as above, except that a Y column type is used for four of the header cells.

....
\newcolumntype{Y}{>{\hspace{0pt}\RaggedRight\arraybackslash}X} % allow hyphenation
....
\begin{table}[htbp]
\setlength\tabcolsep{4pt}
\caption{Mercado de energía eléctrica en Norteamérica}
\label{tab:emna}
\begin{tabularx}{\linewidth}{@{}l
*{2}{S[table-format=7.0]r}
S[table-format=5.0]r
S[table-format=5.1]r @{}}
\toprule
País
& \multicolumn{1}{Y}{Producción [\si{\giga\watt\hour}]} & Fecha
& \multicolumn{1}{Y}{Consumo [\si{\giga\watt\hour}]} & Fecha
& \multicolumn{1}{Y}{Exportaciones [\si{\giga\watt\hour}]} & Fecha
& \multicolumn{1}{Y}{Importaciones [\si{\giga\watt\hour}]} & Fecha \\
\midrule
....


You don't need tabularx, but the stock tabular*. I just abbreviated “Estados Unidos” into “EUA” so to better fit the table in the available space.

Note that non numerical input in S columns should be braced; in this way, siunitx will not try and interpret the text as a number, which is the reason for the error message in the “Exportaciones” cell.

\documentclass[
fontsize=10pt,
paper=letter,
bibliography=totoc,
DIV=9,
titlepage=on
]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage{booktabs}

\usepackage[per-mode=symbol]{siunitx} % Paquete para insertar unidades
\sisetup{
output-decimal-marker = {.},
group-minimum-digits = 4,
range-units = brackets,
list-final-separator = { \translate{and} },
list-pair-separator = { \translate{and} },
range-phrase = { \translate{to (numerical range)} },
}

\begin{document}

\begin{table}[htbp]
\centering
\caption{Mercado de energía eléctrica en Norteamérica}
\label{tab:emna}

\setlength{\tabcolsep}{1pt}% just a minimum
\begin{tabular*}{\linewidth}{
@{\extracolsep{\fill}}
l
S[table-format=7.0]
c
S[table-format=7.0]
c
S[table-format=5.0]
c
S[table-format=5.1]
c
@{}
}
\toprule
País & {Producción} & Fecha
& {Consumo} & Fecha
& {Exportaciones} & Fecha
& {Importaciones} & Fecha \\
& {(\si{\giga\watt\hour})} &
& {(\si{\giga\watt\hour})} &
& {(\si{\giga\watt\hour})} &
& {(\si{\giga\watt\hour})} & \\
\midrule
Canadá  &  612000 & 2007 &  530000 & 2006 & 50120 & 2007 & 19660   & 2007 \\
EUA     & 4167000 & 2007 & 3892000 & 2007 & 20140 & 2007 & 51400   & 2007 \\
México  &  243300 & 2007 &  202000 & 2007 &  1278 & 2007 &   482.2 & 2007 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}


• Thanks for the advices and very interesting comment about the S column type. I'll try to put into braces the headers henceforth. And I'll see if this trick solves the error with the other tables where I had the same problem. – Aradnix Aug 26 '15 at 21:00

This code works. I took the opportunity to improve your table: I don't think you really need a tabularx environment, so I replaced the Y column with a plain l. I also made column head two-lined when I thought it necessary, with the makecell package:

\documentclass[fontsize=10pt, paper=letter, headings=small, bibliography=totoc, DIV=9, headsepline=true, titlepage=on]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage{xspace}
\usepackage{xkeyval}
\usepackage{array,multirow,multicol,rotating,tabularx,ragged2e,booktabs}
\usepackage{ makecell}

\usepackage{rotating} % Paquete para rotar objetos flotantes
\usepackage{colortbl} % Paquete pata colorear tablas
\usepackage[per-mode=symbol]{siunitx} % Paquete para insertar unidades
\sisetup{
output-decimal-marker = {.},
group-minimum-digits = 4,
range-units = brackets,
list-final-separator = { \translate{and} },
list-pair-separator = { \translate{and} },
range-phrase = { \translate{to (numerical range)} },
}
\ExplSyntaxOn
\providetranslation [ to = Spanish ]
{ to~(numerical~range) } { a } % substitute the right word here
\ExplSyntaxOff

\begin{document}

\begin{table}[htb]
\centering
\caption{Reservas y Recursos Prospectivos}
\toprule
\midrule
Convencional & 20589 & 18222 \\
Aguas Someras & 11374 & 7472 \\
Sureste & 11238 & 7472 \\
Norte & 136 & \\
Terrestre & 8818 & 5913 \\
Sur & 4379 & 5371 \\
Chicontepec & 3556 & \\
Burgos & 425 & \\
Resto Norte & 459 & 542 \\
Aguas Profundas & 397 & 4837 \\
Perdido & & 3013 \\
Holok-Han & 397 & 1824 \\
No Convencional & & 5225 \\
\midrule
Total & 20589 & 23447 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


• Thanks for the answer and the improvement of my table. I understand that I can avoid the usage of tabularx but unfortunately is not the same case with another tables. In all cases my problem is the error in siunitx that do not let me compile using the S columns in my tables like this one and others. – Aradnix Jul 31 '15 at 5:03
• Didn't you forget, in the S columns, to enclose the non-numeric cells between brackets? – Bernard Jul 31 '15 at 8:54
• Nope, I reviewed it few times, that's the reason why I asked this. – Aradnix Jul 31 '15 at 21:39
• Could you post an example of non compiling table with the S qualifier (btw, does this one compile for you?)? – Bernard Jul 31 '15 at 22:14
• No, I tried with your example, but if I let empty the cells in the table, my document crashes. If I put a dash it compiles but with errors because of that. – Aradnix Aug 1 '15 at 5:54

First of all in order to answer your question (fix your error): You have used some non-numerical cell in an S column. It should read (or begin with) "e". Just put this cell into curly braces.

Now in general and for your table: Do not use tabularx with numerical data. As your table is too big for the \linewidth, just reduce the width manually.

This would look like this:

% arara: pdflatex

\usepackage[spanish,mexico]{babel}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
%\usepackage{rotating} % do not load that twice
\usepackage{siunitx}
\sisetup{group-minimum-digits = 4}

\begin{document}
\begin{table}[htbp]
\centering
\tabcolsep=1.33ex
\caption{Mercado de energía eléctrica en Norteamérica}
\label{tab:emna}
\begin{tabular}{@{}lS[table-format=7.0]cS[table-format=7.0]cS[table-format=5.0]cS[table-format=5.1]c@{}}
\toprule
País & {Producción} & Fecha & {Consumo}  & Fecha & {Exptciones} & Fecha & {Imptciones} & Fecha \\
& {en \si{\giga\watt\hour}} & & {en \si{\giga\watt\hour}} & & {en \si{\giga\watt\hour}} & & {en \si{\giga\watt\hour}} & \\
\midrule
Canadá &  612000 & 2007 &  530000 & 2006 & 50120 & 2007 & 19660   & 2007 \\
EEUU   & 4167000 & 2007 & 3892000 & 2007 & 20140 & 2007 & 51400   & 2007 \\
México &  243300 & 2007 &  202000 & 2007 &  1278 & 2007 &   482.2 & 2007 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


If you really want to use tabularx, you will find answers here: How to use siunitx and tabularx together?

Do not use brackets around units. That is wrong.

• Thanks for the suggestions, by what I see, and from @egreg response and yours what I need is to put the S column header between curly braces. How do you suggest to manually adjust the space in this long table? Usually I use p{width} but I don't know if there is any better way. – Aradnix Aug 26 '15 at 21:04
• @Aradnix It's the line \tabcolsep=1.33ex. Reduce or increase this value to your needs. The package showframe can help a lot here. For some automatism you should go with table* as egreg did. Do not smash the table too much. It would be better to have two of them or a sideways table or some other trick. – LaRiFaRi Aug 26 '15 at 22:13
• Is the acronym "EEUU" standard in (Mexican) Spanish? – Mico Aug 27 '15 at 4:32
• @Mico there are at least two different systems for create acronyms. One is duplicating letters for create plural, such as in EEUU, and other one that use the first letter of each word no matter if it's plural, such as EUA. Finally is a question of style, but both are correct. – Aradnix Aug 27 '15 at 4:55
• @Aradnix - Thanks for this explanation. I wasn't familiar with this system. – Mico Aug 27 '15 at 4:59