[Tex/LaTex] Decimal alignment in tables with tabularx and multicolumn

multicolumntablestabularx

in my masterthesis I want to create regression tables the numbers in the table are aligned by the decimal point.

Here is a MWE to get an impression what I'm talking about:

\documentclass[10pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}
\begin{document}
\begin{table}
\caption{MWE without multicolumn elements.}
\begin{tabularx}{\textwidth}{XSSSS} % S: align by decimal point (part of the siunitx package)  
\toprule
1&2&3&4&5\\
\midrule  
1 & 94.90 & 5.10 & 0.00 & 0.00 \\  
2 & 4.08 & 88.78 & 6.80 & 0.34 \\  
3 & 0.00 & 4.08 & 91.84 & 4.08 \\  
4 & 1.02 & 0.51 & 5.61 & 92.86 \\  
\bottomrule
\end{tabularx}
Note: bla bla bla bla.
\end{table}
\end{document}

The code above leads to following results:
enter image description here

I am quite satisfied with this result, but if I add \mulitcolumn areas like in the following MWE the compilation process doesn't work:

\documentclass[10pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}
\author{Name of the author}
\begin{document}
\begin{table}
\caption{MWE without multicolumn elements.}
\begin{tabularx}{\textwidth}{XSSSS} % S: align by decimal point (part of the siunitx package)  
\toprule
&\multicolumn{2}{c}{Subset 1}& \multicolumn{2}{c}{Subset 2}\\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& 1\_PR\_bin & 2\_PR\_log & 3\_RE\_bin & 4\_RE\_log \\ 
\midrule  
1 & 94.90 & 5.10 & 0.00 & 0.00 \\  
2 & 4.08 & 88.78 & 6.80 & 0.34 \\  
3 & 0.00 & 4.08 & 91.84 & 4.08 \\  
4 & 1.02 & 0.51 & 5.61 & 92.86 \\  
\bottomrule
\end{tabularx}
Note: bla bla bla bla.
\end{table}
\end{document}

Who can help me to fix this issue? Thank you very much in advance for your help!!

Best Answer

You have table head values starting with numbers but which presumably should not be part of the general column alignment. You'll see odd results even without the \multicolumn if you don't escape these:

& {1\_PR\_bin} & {2\_PR\_log} & {3\_RE\_bin} & {4\_RE\_log} \\ 

I'd also recommend telling siunitx how many digits are in each column using the optional argument to S

\begin{tabularx}{\textwidth}{X*4{S[table-format = 2.2]}} % S: align by decimal point (part of the siunitx package)  
\toprule
&\multicolumn{2}{c}{Subset 1}& \multicolumn{2}{c}{Subset 2}\\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& {1\_PR\_bin} & {2\_PR\_log} & {3\_RE\_bin} & {4\_RE\_log} \\ 
\midrule  
1 & 94.90 & 5.10 & 0.00 & 0.00 \\  
2 & 4.08 & 88.78 & 6.80 & 0.34 \\  
3 & 0.00 & 4.08 & 91.84 & 4.08 \\  
4 & 1.02 & 0.51 & 5.61 & 92.86 \\  
\bottomrule
\end{tabularx}