siunitx を使用して小数点記号を千単位の区切り記号に揃える

siunitx を使用して小数点記号を千単位の区切り記号に揃える

私のテーブルは 2 つの行グループで構成されています。最初のグループには大きな値 (X,XXX) が含まれています。2 番目のグループには小さな値 (0.XXX) が含まれています。Siunitx は、小数点の位置に基づいてすべての数値を揃えます。結果は美しくありません。一部の数値は左に揃えられ、他の数値は右に揃えられています。

小数点記号 (小さい値) が 3 桁ごとの区切り記号 (大きい値) と揃うように数値を揃えることは可能ですか?

以下に表の例を示します。2 列目と 3 列目には現在の状況が表示されます。最後の 2 列は、データの表示方法の例です (Photoshop を使用して編集)。

例

きちんとした解決策が存在しない場合には、ハッキーな解決策も歓迎されます。

私はすでに、表内の小数点記号を変更する方法を思いつきました。最初の行のグループの小数点記号としてコンマを使用できれば、すべてうまくいきます。しかし、私はそれを機能させることができませんでした (LaTeX に関する私の知識はわずかです)。

表に使用されているコード:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\sisetup{group-separator={,},group-minimum-digits={3},output-decimal-marker={.}}

\begin{document}
\begin{tabular}{@{}p{2.3cm}SSp{0.3cm}SS@{}}

\toprule
& \multicolumn{2}{c}{Without Threshold Selector} && \multicolumn{2}{c}{With Threshold Selector}\\
\cmidrule{2-3} \cmidrule{5-6}
& \multicolumn{1}{p{2.3cm}}{\centering{Naive Bayes}} & \multicolumn{1}{p{2.3cm}}{\centering{Logistic}} && \multicolumn{1}{p{2.3cm}}{\centering{Naive Bayes}} & \multicolumn{1}{p{2.3cm}}{\centering{Logistic}}\\
\midrule

True positives  & 2791  & 1831  && 3126     & 3547\\
False positives & 2924  & 995   && 3853     & 3483\\
True negatives  & 36998 & 38927 && 36069    & 36439\\
False negatives & 2498  & 3458  && 2163     & 1742\\

\addlinespace

Sensitivity     & 0.528 & 0.346 && 0.591    & 0.671\\
Precision       & 0.488 & 0.648 && 0.448    & 0.505\\

\bottomrule

\end{tabular}
\end{document}

答え1

この表示形式はお勧めしませんが、確かに実行可能です。 を使用するよりも、配置がsiunitxどのように行われるかに基づいて、ある程度「低レベル」のソリューションを選択するでしょうdcolumn。ここでの戦略はハイブリッド アプローチです。まず、を使用してセルの内容を取得しますcollcell(これは、最初のステージで行うのとほぼ同じですsiunitx)。収集された内容は小数または整数のいずれかであると想定され、.したがって、のクイック チェックが行われます。小数の場合、先頭に 1 桁のパディングが許可され、数値は「そのまま」タイプセットされます。整数の場合、 を追加するかどうかのハードコードされたチェックがあり,、数値が出力にダンプされます。すべてを固定幅のボックスで実行することで、配置が可能になります。

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{collcell}
\newlength\mylength
\AtBeginDocument{\settowidth\mylength{$12.345$}}
\newcolumntype{M}{>{\collectcell\multialign}l<{\endcollectcell}}
\makeatletter
\newcommand*\multialign[1]{%
  \setbox0=\hbox to \mylength{%
    \hfil
    $
      \in@{.}{#1}%
      \ifin@
        \settowidth\mylength{$0$}%
        \hspace{\mylength}%
        \expandafter\@firstofone
      \else
        \expandafter\multialignint
      \fi
        {#1}%
    $%
  }%
  \hfil\box0\hfil
}
\newcommand*\multialignint[1]{%
  \multialignintauxi#1\empty\empty\empty\empty\relax\stop
}
\newcommand*\multialignintauxi{}
\def\multialignintauxi#1#2#3#4#5#6\stop{%
 \ifx#4\empty % Three or fewer digits
   #1#2#3%
 \else
  \ifx#5\empty % Four digits
    #1\mathord,#2#3#4%
  \else % Five digits
    #1#2\mathord,#3#4#5%
  \fi
 \fi
}
\makeatother
\begin{document}
\begin{tabular}{@{}p{2.3cm}MMp{0.3cm}MM@{}}

\toprule
& \multicolumn{2}{c}{Without Threshold Selector} && \multicolumn{2}{c}{With Threshold Selector}\\
\cmidrule{2-3} \cmidrule{5-6}
& \multicolumn{1}{p{2.3cm}}{\centering{Naive Bayes}} & \multicolumn{1}{p{2.3cm}}{\centering{Logistic}} && \multicolumn{1}{p{2.3cm}}{\centering{Naive Bayes}} & \multicolumn{1}{p{2.3cm}}{\centering{Logistic}}\\
\midrule

True positives  & 2791  & 1831  && 3126     & 3547\\
False positives & 2924  & 995   && 3853     & 3483\\
True negatives  & 36998 & 38927 && 36069    & 36439\\
False negatives & 2498  & 3458  && 2163     & 1742\\

\addlinespace

Sensitivity     & 0.528 & 0.346 && 0.591    & 0.671\\
Precision       & 0.488 & 0.648 && 0.448    & 0.505\\

\bottomrule
\end{tabular}
\end{document}

関連情報