20

I would like to construct a table which looks like a booktabs table (but without using the package booktabs). Instead of \cmidrule, I used \cline, which comes pretty close (see below), but the lines drawn with \cline are too wide, so that they touch... and therefore it's difficult for the eye to determine where the groups start/end. Is there a solution to this? (without using additional packages).

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[table]{xcolor}

\begin{document}

% my trial with \cline
\begin{table}[htbp]
  \centering
  \begin{tabular}{rrrrrrrrr}
    \hline
    Sex & \multicolumn{4}{c}{Male} & \multicolumn{4}{c}{Female} \\
    \cline{2-5} \cline{6-9}
    Age & \multicolumn{2}{c}{Child} & \multicolumn{2}{c}{Adult} & \multicolumn{2}{c}{Child} & \multicolumn{2}{c}{Adult} \\
    \cline{2-3} \cline{4-5} \cline{6-7} \cline{8-9}
    {Class \ Survived} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} \\
    \hline
    1st & 0 & 5 & 118 & 57 & 0 & 1 & 4 & 140 \\
    2nd & 0 & 11 & 154 & 14 & 0 & 13 & 13 & 80 \\
    3rd & 35 & 13 & 387 & 75 & 17 & 14 & 89 & 76 \\
    Crew & 0 & 0 & 670 & 192 & 0 & 0 & 3 & 20 \\
    \hline
  \end{tabular}
\end{table}

% with booktabs
\begin{table}[htbp]
  \centering
  \begin{tabular}{rrrrrrrrr}
    \toprule
    Sex & \multicolumn{4}{c}{Male} & \multicolumn{4}{c}{Female} \\
    \cmidrule(lr){2-5} \cmidrule(lr){6-9}
    Age & \multicolumn{2}{c}{Child} & \multicolumn{2}{c}{Adult} & \multicolumn{2}{c}{Child} & \multicolumn{2}{c}{Adult} \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9}
    {Class \ Survived} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} \\
    \midrule
    1st & 0 & 5 & 118 & 57 & 0 & 1 & 4 & 140 \\
    2nd & 0 & 11 & 154 & 14 & 0 & 13 & 13 & 80 \\
    3rd & 35 & 13 & 387 & 75 & 17 & 14 & 89 & 76 \\
    Crew & 0 & 0 & 670 & 192 & 0 & 0 & 3 & 20 \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

enter image description here

20
  \begin{tabular}{@{\extracolsep{4pt}}rrrrrrrrr@{}}

enter image description here

  • ... that's quite embarrassing I forgot that one :-) Thanks, David. – Marius Hofert Mar 5 '13 at 14:29
  • 1
    Is there a way to assign \extracolsep without setting the horizontal space between columns (or in this case before the first and to preserve symmetry after the last) to zero? \begin{tabular}{@{\extracolsep{4pt}}@{\kern\tabcolsep}rrrrrrrrr}? – Qrrbrbirlbel Mar 5 '13 at 14:45
  • @Qrrbrbirlbel yes you can use array package ! instead of @ it is the same except it doesn't remove the default space – David Carlisle Mar 5 '13 at 15:07
  • What does the @ do? What does the {} do? – Martin Thoma May 8 '17 at 13:17
  • 2
    @MartinThoma that is very basic latex syntax, probably best not to ask as a comment on a 4-year old question @{zzz} adds zzz between the columns on each row. – David Carlisle May 8 '17 at 13:19

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.