4

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.

  • The main issue is of course that the two column headers are wider than then two colums. Couldn't you drop the word "Detections" from them, and for example explain that in the caption to the table. – daleif Apr 1 at 7:54
  • Of course, that is an option. But in my opinion, that is less readable, when there should exist a solution to align it the way I want. – Andreas Apr 1 at 8:10
  • 1
    I just tested your code, and I would actually be more extreme an and only use Ignoring and Approving, much less clutter for the reader to deal with. And I'd remove the @{} from those headers, looks strange. – daleif Apr 1 at 8:15
2

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}
4

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} 
  • Note also the use of two \addlinespace instructions to provide some visual grouping inside the body of the table. – Mico Apr 1 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.