[Tex/LaTex] Use column type S, from siunitx package with complex table headings

multirows-column-typesiunitx

I have a table with a complex heading using multirow and multicol packages. I'd like to have the second column of the following table as S type from siunitx package for to align the numbers by its decimal separator, however I failed. Any help, please?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow,multicol}
\begin{document}

\begin{table}[htb]
\footnotesize
\centering
\caption{Example Table}
\begin{tabular}{ccSS}% <--- HERE
\midrule
\multirow{2}{*}{\textbf{Column 1}} & 
\multirow{2}{*}{\textbf{%
\begin{tabular}[c]
{@{}c@{}}Column 2\\
(\si{\g/\mL})
\end{tabular}}} &
\multicolumn{2}{c}{\textbf{Column 3 (\si{\ug/\L})}} \\
\cmidrule{3-4}& &
\textbf{Column 3.1} & \textbf{Column 3.2}\\
\midrule
AE1 &  3.45 & \multicolumn{ 2}{c}{Some text} \\ 
AE2 & 20.65 & 50 & 4.5 \\ 
AE3 & 12.67 & 20 & 7.5 \\ 
AE4 & 0.78 & 75 & 12.09 \\ 
AE5 & 3.098 & 100 & 14 \\
\midrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Best Answer

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{booktabs, multirow}
\usepackage{siunitx}

\begin{document}

\begin{table}[htb]
\centering
%\footnotesize
\renewcommand\multirowsetup{\centering}% for centering text in multirow cells
\caption{Example Table}
\begin{tabular}{cS[table-format=2.3]
                 S[table-format=3.0]
                 S[table-format=2.2]}% <--- HERE added S column type
    \toprule
\multirow{2}{*}{\textbf{Column 1}} 
    &   {\multirow{2}{12ex}{\textbf{Column 2}\\(\si{\g/\mL})}} % enclosed in {...} 
                                                               % with defined width is possible write text in more lines
        &   \multicolumn{2}{c}{\textbf{Column 3 (\si{\ug/\L})}}     \\
    \cmidrule{3-4}& &
\textbf{Column 3.1} & \textbf{Column 3.2}   \\
    \midrule
AE1 &  3.45 & \multicolumn{2}{c}{Some text} \\
AE2 & 20.65 & 50 & 4.5                      \\
AE3 & 12.67 & 20 & 7.5                      \\
AE4 &  0.78 & 75 & 12.09                    \\
AE5 & 3.098 & 100 & 14                      \\
    \bottomrule
\end{tabular}
\end{table}
\end{document}
Related Question