文書内のすべての数値を小数点以下の桁数に変換します

文書内のすべての数値を小数点以下の桁数に変換します

すべての数字を小数点第 2 位に自動的にフォーマットする必要がある表があります。これは可能ですか? それとも、ドキュメント全体をフォーマットする必要がありますか?

編集:

回答で提案されたコードを適用しましたが、残念ながら私の特定のテーブルでは機能しないようです。それに応じて適応させる方法について何かアイデアはありますか?

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\sisetup{
table-number-alignment = center,
table-figures-integer = 1,
table-figures-decimal = 2
}

\begin{table}[thb]

\caption{\label{labelname}Table Caption}

\scriptsize
{\centering \begin{tabular
{lr@{\hspace{0cm}}c@{\hspace{0cm}}rr@{\hspace{0cm}}c@{\hspace{0cm}}r@{\hspace{0.1cm}}cr@{    space{0cm}}c@{\hspace{0cm}}r@{\hspace{0.1cm}}cr@{\hspace{0cm}}c@{\hspace{0cm}}r@{\hspace{0
1cm}}cr@{\hspace{0cm}}c@{\hspace{0cm}}r@{\hspace{0.1cm}}cr@{\hspace{0cm}}c@{\hspace{0cm}}r
{\hspace{0.1cm}}cr@{\hspace{0cm}}c@{\hspace{0cm}}r@{\hspace{0.1cm}}cr@{\hspace{0cm}}c@{\hs
ace{0cm}}r@{\hspace{0.1cm}}c}

\\
\hline
Dataset & \multicolumn{3}{c}{ConjunctiveRule }& \multicolumn{4}{c}{DecisionTable } &
\multicolumn{4}{c}{DTNB } & \multicolumn{4}{c}{JRip} & \multicolumn{4}{c}{NNge} &
\multicolumn{4}{c}{OneR} & \multicolumn{4}{c}{PART} & \multicolumn{4}{c}{Ridor} \\
\hline
Number correct & 9.5900 & $\pm$ & 1.16 & 9.5600 & $\pm$ & 1.22 &         & 9.5600 & $\pm$ &
1.22 &         & 9.5000 & $\pm$ & 1.24 &         & 8.9500 & $\pm$ & 1.34 &         & 9.6000
& $\pm$ & 1.16 &         & 9.3000 & $\pm$ & 1.34 &         & 9.1700 & $\pm$ & 1.42 &        \

\end{tabular} \scriptsize \par}
\end{table}
\end{document}

答え1

各列を小数点付きでS-columns として定義する必要があります。

表には 31 列あり、小数点付きの列、数学記号付きの列、空の列があります。空の列にはemdash(追跡のため) を入れました。

これは MWE (最小限の動作例) です。私は、scrartcl高い DIV 係数と横長モードを使用して、表をページの余白の間に押し込んでいます。正しいパラメータで -package を使用することで、同じことを実現できますgeometry

\documentclass[a4paper,landscape,DIV=20]{scrartcl}
\usepackage{siunitx}
\begin{document}
\sisetup{
  table-number-alignment = center,
  table-figures-integer = 1,
  table-figures-decimal = 2
}
\begin{table}[thb]
\caption{\label{labelname}Table Caption}
\centering\tiny
\begin{tabular}{
    l
    S[table-auto-round]
    c
    S[table-auto-round]
    S[table-auto-round]
    c
    S[table-auto-round]
    l
    S[table-auto-round]
    c
    S[table-auto-round]
    l
    S[table-auto-round]
    c
    S[table-auto-round]
    l
    S[table-auto-round]
    c
    S[table-auto-round]
    l
    S[table-auto-round]
    c
    S[table-auto-round]
    c
    S[table-auto-round]
    c
    S[table-auto-round]
    c
    S[table-auto-round]
    c
    S[table-auto-round]
    l}

Dataset & \multicolumn{3}{c}{ConjunctiveRule }& \multicolumn{4}{c}{DecisionTable } &
\multicolumn{4}{c}{DTNB } & \multicolumn{4}{c}{JRip} & \multicolumn{4}{c}{NNge} &
\multicolumn{4}{c}{OneR} & \multicolumn{4}{c}{PART} & \multicolumn{4}{c}{Ridor} \\

Number correct & 
9.5900 & 
$\pm$ & 
1.16 & 
9.5600 & 
$\pm$ &
1.22 &
--- &
9.5600 &
$\pm$ &
1.22 &
--- & 
9.5000 & 
$\pm$ & 
1.24 &
--- &
8.9500 & 
$\pm$ &
 1.34 &
--- & 
9.6000 & 
$\pm$ & 
1.16 & 
--- & 
9.3000 & 
$\pm$ 
& 1.34 & 
--- & 
9.1700 & 
$\pm$ &
 1.42 &
--- \\ 
\end{tabular}
\end{table}
\end{document}

ここに画像の説明を入力してください

答え2

57ページを参照siunitxドキュメンテーション。

小さな例:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\sisetup{
  table-number-alignment = center,
  table-figures-integer = 1,
  table-figures-decimal = 2
}
\begin{tabular}{
    S[table-auto-round]
  }
  2.\\
  2.3\\
  2.34\\
  2.345
\end{tabular}
\end{document}

関連情報