siunitx를 사용하여 소수점 표시를 천 단위 구분 기호로 정렬

siunitx를 사용하여 소수점 표시를 천 단위 구분 기호로 정렬

내 테이블은 두 개의 행 그룹으로 구성됩니다. 첫 번째 그룹에는 큰 값(X,XXX)이 포함되어 있습니다. 두 번째 그룹에는 더 작은 값(0.XXX)이 포함됩니다. Siunitx는 소수점 위치를 기준으로 모든 숫자를 정렬합니다. 결과는 아름답지 않습니다. 일부 숫자는 왼쪽으로 정렬되어 있는 반면 다른 숫자는 오른쪽으로 정렬되어 있습니다.

소수점 표시(작은 값)가 천 단위 구분 기호(큰 값)와 정렬되도록 숫자를 정렬할 수 있습니까?

다음은 테이블의 예입니다. 두 번째와 세 번째 열은 현재 상황을 보여줍니다. 마지막 두 열은 데이터가 어떻게 표시되기를 원하는지에 대한 예입니다(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수집된 자료는 십진수 또는 정수로 간주되므로 빠른 확인이 .이루어집니다. 소수의 경우 앞에 한 자리의 패딩이 허용되며 숫자는 '있는 그대로' 조판됩니다. 정수의 경우 a를 추가하기 위한 하드 코딩된 검사가 있으며 ,숫자가 출력에 덤프됩니다. 고정 너비 상자에서 모든 작업을 수행하면 정렬이 가능합니다.

\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}

관련 정보