
私はいくつかの表で作業していますが、数字の配置には、siunitx
Micoが助けてくれたので、通常はパッケージを使用しています。この質問。
しかし、これらの新しいテーブルには、解決方法がわからないエラーがありました。
siunitx error: "invalid-number" Invalid numerical input 'e'.
For immediate help type H <return>. \end{tabularx}
私はこれに関して次のような質問を見つけました:質問1そして質問2残念ながら同じケースではないので、解決につながる手がかりは見つかりませんでした。
私の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}
S
中央の列と右の列で列タイプを使用しようとしましたが、前述のエラーのため使用できません。単純にS
列を使用してみましたが、成功せず、その後もS[table-format=5.0]
機能しませんでした。私のテーブルに何が問題なのでしょうか?
アップデート
S
どちらの回答も非常に興味深く、役に立ちましたが、残念ながら私の問題は解決しません。必要な列タイプをテーブルに追加できません。
ここで、現在同じ問題で動作しているテーブルを追加します。その間、列タイプを使用しましたY
が、結果は満足のいくものではありませんでした。
私のプリアンブルにあるパッケージの 1 つが原因だと思います。MWE はスムーズに動作しているようなので、それを検出できるかどうか確認してください。
答え1
(OP が MWE の表を変更した後、回答を書き直しました。)
S
次のソリューションでは、4つの「GWh」列に列タイプを使用できます。そして環境を使用できますtabularx
(テーブルの幅が に等しいことを保証するため\linewidth
)。トリックは、S
数字に を使用し、ヘッダーにC
( の中央揃えバージョン) を使用することです。X
表のヘッダーを再編成したことにお気づきでしょう。元の設定では、重要な 4 つのヘッダー単語 (、、、) すべてに改行が必要です。Producción
このような単語のハイフンの使用は (可能な限り) 避けたほうがConsumo
よいと思います。ヘッダーを角括弧で囲んだままにしていますが、これは必要ないかもしれません。Exportaciones
Importaciones
GWh
(プリアンブル コードを簡素化および合理化するために、テーブルの生成に必須ではないと思われるパッケージもすべて削除しました。)
\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}
補遺: これは同じテーブルですが、ヘッダー マテリアルの再編成はありません。コードは上記と同じですが、Y
ヘッダー セルの 4 つに列タイプが使用されています。
....
\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
....
答え2
は必要ありませんtabularx
が、在庫は必要ですtabular*
。表を利用可能なスペースにうまく収めるために、「Estados Unidos」を「EUA」に省略しました。
列内の数値以外の入力は中S
括弧で囲む必要があることに注意してください。こうすることで、siunitx
テキストを数値として解釈することがなくなり、「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}
答え3
このコードは動作します。この機会にテーブルを改良しました。環境は本当に必要ないと思うので、列をプレーンな にtabularx
置き換えました。また、必要だと思ったときに、パッケージを使用して列見出しを 2 行にしました。Y
l
makecell
\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}
答え4
まず、あなたの質問に答えるために(あなたのエラーを修正するために):列に数値以外のセルが使用されていますS
。それは「e」と表示される(または「e」で始まる)必要があります。このセルを中括弧で囲むだけです。
一般的に、テーブルについては、tabularx
数値データには使用しないでください。テーブルが に対して大きすぎる場合は\linewidth
、幅を手動で縮小してください。
次のようになります:
% 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}
本当に を使用したい場合はtabularx
、ここで答えが見つかります:siunitx と tabularx を一緒に使用するにはどうすればいいですか?
単位の前後に括弧を使用しないでください。これは誤りです。