[Tex/LaTex] siunitx error: “invalid-number” Invalid numerical input ‘e’

siunitxtables

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.

Best Answer

(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.)

enter image description here

\documentclass[fontsize=10pt,paper=letter,headings=small,bibliography=totoc,
         DIV=9,headsepline=true,titlepage=on]{scrartcl}
\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.

enter image description here

....
\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
....