My table consists of two groups of rows. The first group contains large values (X,XXX). The second groups contains smaller values (0.XXX). Siunitx aligns all numbers based on the position of the decimal marker. The result isn't beautiful: some numbers are aligned very much the left, while others are very much to the right.
Is it possible to align the numbers so that the decimal markers (from the small values) are aligned with the thousands separators (from the large values)?
Here's an example of the table. The second and third column show the current situation. The last two columns are an example of how I'd like the data to appear (edited using Photoshop).
If a neat solution doesn't exist, a hacky solution would be welcome as well.
I already thought of a way to change the decimal marker within the table: if I could have a comma as decimal marker for the first group of rows, everything would be fine. However, I couldn't get that to work (with my little knowledge of LaTeX).
Code used for the table:
\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}
Best Answer
While I would not recommend this display form, it is certainly doable. Rather than use
siunitx
I'd probably go for a 'low level' solution based to some extent on howdcolumn
does alignment. The strategy here is a hybrid approach. First, the cell content is grabbed usingcollcell
(which does much the same assiunitx
does at the first stage). The collected material is assumed to be either a decimal or integer number, and a quick check for.
is therefore made. For decimals, one digit of padding is allowed for at the front and the number is typeset 'as is'. For integers, there is a hard-coded check for adding a,
and the number is dumped into the output. Doing everything in a fixed-width box allows for alignment: