Well I've been working in some tables and for the number alignment I normally use the siunitx
package 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 atabularx
environment (to assure that the width of the table is equal to\linewidth
). The trick -- such as it is -- consists of usingS
for the numbers andC
(a centered version ofX
) 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
, andImportaciones
. I think it's better to avoid (as much as possible) the hyphenation of such words. I left the square brackets around theGWh
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.)
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.