5

After looking at multiple tex.stackexchange questions, I'm still having trouble getting the alignment of multiple columns right.

Here's my code

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{@{}lcccc@{}}
    \toprule
        & \multicolumn{2}{@{}c}{Ignoring Unlabeled Detections} 
        & \multicolumn{2}{c@{}}{Approving Unlabeled Detections}\\
    \cmidrule(r){2-3} 
    \cmidrule(r){4-5}
        & Recall  & Precision    & Recall  & Precision  \\
    \cmidrule(r){2-3} 
    \cmidrule(r){4-5}
    % \midrule
    count           & 513     & 446         &  529     & 484     \\
    mean            & 0.428   & 0.787       &  0.507   & 0.841   \\
    std             & 0.343   & 0.365       &  0.337   & 0.310   \\
    min             & 0.000   & 0.000       &  0.000   & 0.000   \\
    \ensuremath{Q_1}& 0.000   & 0.667       &  0.286   & 0.800   \\
    \ensuremath{Q_2}& 0.500   & 1.000       &  0.500   & 1.000   \\
    \ensuremath{Q_3}& 0.667   & 1.000       &  0.750   & 1.000   \\
    max             & 1.000   & 1.000       &  1.000   & 1.000   \\
    \bottomrule
\end{tabular}

\end{document}

Which gives the result Result of code run

I would naturally like the recall and precision columns to be equally spaced beneath each respective title.

Andreas
  • 259

2 Answers2

5

You could give the table header more visual structure, along the lines of the following example, by creating an additional line. You're of course entirely free to modify the proposed overall header, "Actions regarding unlabeled detections".

enter image description here

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{@{} l cccc @{}}
    \toprule
    & \multicolumn{4}{c@{}}{Actions regarding unlabeled detections}\\
    \cmidrule(l){2-5}
    & \multicolumn{2}{c}{Ignore} & \multicolumn{2}{c@{}}{Approve}\\
    \cmidrule(lr){2-3} \cmidrule(l){4-5}
    & Recall & Precision & Recall & Precision  \\
    \midrule
    count & 513     & 446         &  529     & 484     \\
    \addlinespace
    mean  & 0.428   & 0.787       &  0.507   & 0.841   \\
    std   & 0.343   & 0.365       &  0.337   & 0.310   \\
    \addlinespace
    min   & 0.000   & 0.000       &  0.000   & 0.000   \\
    $Q_1$ & 0.000   & 0.667       &  0.286   & 0.800   \\
    $Q_2$ & 0.500   & 1.000       &  0.500   & 1.000   \\
    $Q_3$ & 0.667   & 1.000       &  0.750   & 1.000   \\
    max   & 1.000   & 1.000       &  1.000   & 1.000   \\
    \bottomrule
\end{tabular}
\end{center}
\end{document} 
Mico
  • 506,678
  • Note also the use of two \addlinespace instructions to provide some visual grouping inside the body of the table. – Mico Apr 01 '19 at 09:42
3

Here is a version that keeps the headers as they are and sets the column width of the second to fifth column with respect to the width of the corresponding multirow header.

However, I personally would prefer Mico's solution as there are quite large white spaces in my version of the table.

enter image description here

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{calc}
\usepackage{array}

\begin{document}

\begin{tabular}{@{}l*{4}{>{\centering\arraybackslash}p{\widthof{Approving Unlabeled Detections}/2 - 2\tabcolsep}}@{}}
    \toprule
        & \multicolumn{2}{@{}c}{Ignoring Unlabeled Detections} 
        & \multicolumn{2}{c@{}}{Approving Unlabeled Detections}\\
    \cmidrule(r){2-3} 
    \cmidrule(r){4-5}
        & Recall  & Precision    & Recall  & Precision  \\
    \cmidrule(r){2-3} 
    \cmidrule(r){4-5}
    % \midrule
    count           & 513     & 446         &  529     & 484     \\
    mean            & 0.428   & 0.787       &  0.507   & 0.841   \\
    std             & 0.343   & 0.365       &  0.337   & 0.310   \\
    min             & 0.000   & 0.000       &  0.000   & 0.000   \\
    $Q_1$           & 0.000   & 0.667       &  0.286   & 0.800   \\
    $Q_2$           & 0.500   & 1.000       &  0.500   & 1.000   \\
    $Q_3$           & 0.667   & 1.000       &  0.750   & 1.000   \\
    max             & 1.000   & 1.000       &  1.000   & 1.000   \\
    \bottomrule
\end{tabular}

\end{document}
leandriis
  • 62,593