
Bem, tenho trabalhado em algumas tabelas e para o alinhamento dos números normalmente uso o siunitx
pacote já que o Mico me ajudouessa questão.
Mas tive nessas novas tabelas um erro que não sei como resolver.
siunitx error: "invalid-number" Invalid numerical input 'e'.
For immediate help type H <return>. \end{tabularx}
Encontrei estas perguntas sobre isso:questão 1eQuestão 2. Infelizmente não é o mesmo caso e não encontrei pistas que me levem à solução.
Meu MWE é:
\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}
Tento usar S
o tipo de coluna nas colunas do meio e da direita, mas não consigo devido ao erro mencionado anteriormente. Tentei usar simplesmente S
coluna sem sucesso e depois, S[table-format=5.0]
mas não funcionou. O que há de errado com minhas tabelas?
Atualizar
Embora ambas as respostas tenham sido muito interessantes e úteis, receio que o meu problema persista. Não consigo adicionar colunas ao meu tipo de tabela S
e preciso delas.
Agora adiciono uma tabela que atualmente funciona com o mesmo problema, na qual Y
entretanto usei o tipo de coluna mas o resultado não tem sido satisfatório.
Acho que um dos pacotes do meu preâmbulo é o responsável, veja se consigo detectá-lo porque o MWE parece funcionar perfeitamente.
Responder1
(Reescrevi a resposta depois que o OP alterou a tabela no MWE.)
A solução a seguir permite usar o S
tipo de coluna para as quatro colunas "GWh"epermite usar um tabularx
ambiente (para garantir que a largura da tabela seja igual a \linewidth
). O truque - tal como é - consiste em usar S
para os números e C
(uma versão centralizada de X
) para os cabeçalhos.
Você observará que reorganizei o cabeçalho da tabela. Sua configuração original requer quebras de linha para todas as quatro palavras de cabeçalho importantes - Producción
, Consumo
, Exportaciones
e Importaciones
. Acho melhor evitar (tanto quanto possível) a hifenização dessas palavras. Deixei os colchetes ao redor dos GWh
cabeçalhos; no entanto, eles podem não ser necessários.
(Para simplificar e agilizar o código do preâmbulo, também removi todos os pacotes que não parecem ser essenciais para gerar a tabela.)
\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}
Termo aditivo: Aqui está a mesma tabela, mas sem a reorganização do material do cabeçalho. O código é o mesmo acima, exceto que um Y
tipo de coluna é usado para quatro das células do cabeçalho.
....
\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
....
Responder2
Você não precisa tabularx
, mas o estoque tabular*
. Acabei de abreviar “Estados Unidos” para “EUA” para melhor encaixar a mesa no espaço disponível.
Observe que a entrada não numérica nas S
colunas deve ser entre colchetes; desta forma, siunitx
não tentará interpretar o texto como um número, razão pela qual aparece a mensagem de erro na célula “Exportaciones”.
\documentclass[
fontsize=10pt,
paper=letter,
headings=small,
bibliography=totoc,
DIV=9,
headsepline=true,
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}
Responder3
Este código funciona. Aproveitei para melhorar sua tabela: não acho que você realmente precise de um tabularx
ambiente, então troquei a Y
coluna por um plain l
. Também fiz cabeçalho de coluna com duas linhas quando achei necessário, com o makecell
pacote:
\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}
\label{tab:RecOtorgados}%{0.85\linewidth}
\begin{tabular}{@{}l@{\qquad}S[table-format=5.0]S[table-format=5.0] @{}}%
\toprule
Tipo/Área & {\thead{Recursos 2P \\{} [MMBPCE]}} & {\thead{Recursos Prospectivo\\{} [MMBPCE]}} \\
\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}
Responder4
Em primeiro lugar, para responder à sua pergunta (corrija o seu erro): Você usou alguma célula não numérica em uma S
coluna. Deve ler (ou começar com) "e". Basta colocar esta célula entre chaves.
Agora de forma geral e para sua tabela: Não use tabularx
com dados numéricos. Como sua mesa é muito grande para o \linewidth
, basta reduzir a largura manualmente.
Isso ficaria assim:
% arara: pdflatex
\documentclass[fontsize=10pt,paper=letter,headings=small,DIV=9,headsepline=true]{scrartcl}
\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}
Se você realmente quiser usar tabularx
, encontrará respostas aqui:Como usar siunitx e tabularx juntos?
Não use colchetes ao redor das unidades. Isso esta errado.