I am trying to format a table with tabularx, see below.
The table content does not matter, I just put some random numbers there. As you can see, I tried to group the four categories (Apple, ...) and a total one (columns 2-4) into blocks of three columns using custom column types and modifying column separators.
I spent quite some time on trying to properly align the cmidrules below the categories, but I think they are matching the column groups properly now. The following two problems remain:
- I introduced a new column type for centering the column contents, but apparently everything is still left-aligned.
- I need to align possibly negative values in the last row with the exclusively positive numbers in the top rows. So I guess this means that I don't want to center the columns anyway, but need them to be right-justified. I have also read about siunitx column types, but could not successfully integrate it into my table.
I have attached a MWE. Thanks for your help in advance!
\documentclass[11pt]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[scaled=1]{uarial}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{siunitx}
\begin{document}
\newcommand{\ap}[1]{AP\textsubscript{#1}}
\newcommand{\apavg}[0]{AP\textsubscript{\(\varnothing\)}}
\begin{figure}[!htbp]
\centering
\tiny
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered X-column
\newcolumntype{B}{*{3}{C}} % block of 3 columns
\newcolumntype{d}{@{\hspace{3\tabcolsep}}} % 150% spacing
\begin{tabularx}{\textwidth}{c d B d B d B d B d B @{\hspace{2\tabcolsep}}}
\toprule
\multirow{2}[3]{*}{Model} & \multirow{2}[3]{*}{\ap{50}} & \multirow{2}[3]{*}{\ap{75}} & \multirow{2}[3]{*}{\apavg} & \multicolumn{3}{@{}cd}{Apple} & \multicolumn{3}{@{}cd}{Banana} & \multicolumn{3}{@{}cd}{Potato} & \multicolumn{3}{@{}c}{Orange} \\ \cmidrule(r{2\tabcolsep}){5-7} \cmidrule(r{2\tabcolsep}){8-10} \cmidrule(r{2\tabcolsep}){11-13} \cmidrule(r{\tabcolsep}){14-16}
& & & & \ap{50} & \ap{75} & \apavg & \ap{50} & \ap{75} & \apavg & \ap{50} & \ap{75} & \apavg & \ap{50} & \ap{75} & \apavg \\
\midrule
Baseline & \num{0.100} & \num{0.460} & \num{0.810} & \num{0.210} & \num{0.450} & \num{0.520} & \num{0.880} & \num{0.020} & \num{0.080} & \num{0.240} & \num{0.080} & \num{0.600} & \num{0.050} & \num{0.990} & \num{0.030} \\
Improved & \num{0.200} & \num{0.360} & \num{0.860} & \num{0.390} & \num{0.400} & \num{0.600} & \num{0.900} & \num{0.020} & \num{0.080} & \num{0.200} & \num{0.080} & \num{0.600} & \num{0.100} & \num{0.990} & \num{0.100} \\
\(\Delta\) & \num{0.100} & \num{-0.100} & \num{0.050} & \num{0.180} & \num{-0.050} & \num{0.080} & \num{0.020} & \num{0.000} & \num{0.000} & \num{-0.040} & \num{0.000} & \num{0.000} & \num{0.050} & \num{0.000} & \num{0.070} \\
\bottomrule
\end{tabularx}
\end{figure}
\end{document}
S
column type from thesiunitx
package?