1

I have a table using rules from booktabs. However, I have vertical space constraints and don't want to use subcaption with their subtable. I also have horizontal space constraints, so the column for the group should be minimal.

As a first approach, I do use bigdelim and brackets for grouping.

MWE

A possible MWE looks like the following:

\documentclass{article}

\usepackage{booktabs, bigdelim, rotating}

\begin{document}
\begin{table}[htbp]
\begin{tabular}{llcc}
\toprule
& header1 & header 2 & header 3 \\
\cmidrule{2-4}
\ldelim\{{4}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group1}}] & 1 & a & g \\
& 2 & b & h \\
& 3 & c & i \\
& 3 & c & i \\
\ldelim\{{6}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group2}}] & 4 & d & j \\
& 5 & e & k \\
& 6 & f & l \\
& 7 & g & m \\
& 8 & h & n \\
& 9 & i & o \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

grouping rows of a table

However, I don't want to have the "group" column being captured by the horizontal lines, I don't think that is aesthetic. I used the cmidrule command from booktabs to reduce their length already. However, there is (understandably) no such thing for \toprule and \bottomrule

Question

  1. Is their a solution to have a booktabs without having the \toprule and \bottomrule showing on the "group" column? (I can only think of writing my own command for, e.g. \ctoprule, which is using \cmidrule but all rules from \toprule for, e.g., thickness and spaces, apply.)

  2. Is there a better solution to achieve that grouping with sticking to the booktabs package?

  • Why not use a horizontal line to separate the groups and remove the brackets? – leandriis Aug 9 at 14:46
  • That is an option @leandriis (also in addition to what I have so far). The groupX entries however will then look funny when rotated (but I need them rotated because of space constraints). Maybe I don't fully comprehend your suggestion though. – Marcus Aug 9 at 14:51
  • 1
    The following came to my mind: i.stack.imgur.com/5Eh18.png – leandriis Aug 9 at 15:00
  • Thank you! It for some reason doesn't appeal to me though, as the rotated text feels out of context and without a header for the column, it feels "untidy". I will give it a day and have a look again :) – Marcus Aug 9 at 17:00
  • According to section 5 in the booktabs-manual, trimming of \toprule and \bottomrule is implemented for longtable. That package may be uses for all tabular, unless you need floating. Maybe you can build the table as a longtable? – Sveinung Aug 9 at 19:07
1

Why not just use a thicker cmidrule? As far as I can see, the spacing are approximately the same, and it can be adjusted. I also suggest to remove rightmost side bearing, and trim the left side of the cmidrules. You may also consider to ad a small space between the groups, 0.75ex was enough.

However, according to the booktabs manual section 5, booktabs together with longtable implements trimming of all type of rules. The maintainer suggest to use longtable for tabulars if you need trimmable toprule and bottomrule. I have implemented this in the examples below. The trimming factor is little bit of guesswork, unless you set a fixed width of the first column, or has the skill to implement code to read the .aux-file or measure the first column. In the last version, array got new W- and w-columns, where you can specify alignment and width. I have used a 4mm w-column. The trimming factor should then be 4mm+2\tabcolseps+0.75ex (standard trimming factor see manual p. 4):

longtable

I have improve the code since yesterday:

  1. I have changed the second parameter of \ldelim to {*} to get rid of two Overfull hbox with 10.[...]pt error message. It is still left an Underfull vbox... message, but I leave it for now.
  2. I have changed the \tabcolsep to 0.5em instead of a fixed number of point.
  3. I increased the left column to 5 mm and consequently the correction factor for the toprule and bottomrule. This gives a little more air in the tabular.
  4. The correct trimming factor for cmidrule etc. should be \tabcolsep, not 0.75ex. If you prefer, you may subtract 1pt so the line is not absolutely flush with the text.

enter image description here

\documentclass{article}

\usepackage{booktabs, bigdelim, rotating, longtable, array}
\setlength{\tabcolsep}{0.5em}   % As recommended by James Felici ‘The Complete Manual of Typography’
\begin{document}

%\begin{table}[htbp]
\begin{longtable}[l]{w{l}{5mm}lcc@{}}
\toprule(l{\dimexpr(5mm+3\tabcolsep)})
& header1 & header 2 & header 3
\endfirsthead
\cmidrule(l{\tabcolsep}){2-4}
\ldelim\{{4}{*}[\parbox{4mm}{\rotatebox[origin=c]{90}{group1}}] & 1 & a & g \\
& 2 & b & h \\
& 3 & c & i \\
& 3 & c & i \\\addlinespace[0.75ex]
\ldelim\{{6}{*}[\parbox{4mm}{\rotatebox[origin=c]{90}{group2}}] & 4 & d & j \\
& 5 & e & k \\
& 6 & f & l \\
& 7 & g & m \\
& 8 & h & n \\
& 9 & i & o \\
\bottomrule(l{\dimexpr(5mm+3\tabcolsep)})
\end{longtable}
%\end{table}

\end{document}

tabular and modified cmidrule

enter image description here

\documentclass{article}

\usepackage{booktabs, bigdelim, rotating}

\begin{document}
\begin{table}[htbp]
\begin{tabular}{llcc@{}}
\cmidrule[\heavyrulewidth](l){2-4}
& header1 & header 2 & header 3 \\
\cmidrule(l){2-4}
\ldelim\{{4}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group1}}] & 1 & a & g \\
& 2 & b & h \\
& 3 & c & i \\
& 3 & c & i \\\addlinespace[0.75ex]
\ldelim\{{6}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group2}}] & 4 & d & j \\
& 5 & e & k \\
& 6 & f & l \\
& 7 & g & m \\
& 8 & h & n \\
& 9 & i & o \\
\cmidrule[\heavyrulewidth](l){2-4}
\end{tabular}
\end{table}

\end{document}
  • thank you for your answer! I assume your question was rhetorical, but yes, I thought about adapting cmidrule and make a custom command for [top|buttom]rule based on that (see question #1). However, I thought there might be more cleverness behind it then just the thickness. – Marcus Aug 9 at 16:47
  • 1
    @Marcus I wanted to give support to your principle to keep it simple. – Sveinung Aug 9 at 18:11
  • thank you a lot for these two great solutions. I completely missed the part that [top|bottom]rule are trimmable when using longtable. Your both solutions look really nice and can be also processed with tools like, e.g., csvsimple. I personally prefer the longtable version as it seems to be the solution closest to the booktabs package. Your suggested spacing between the groups makes it indeed more readable. Also, as you hinted in longtable#4, I ending up using \cmidrule(l{\dimexpr(\tabcolsep-1pt)}){2-4} so the rules don't perfectly align with the text of the first column. – Marcus Aug 31 at 14:34
  • Thank you for the feedback, @Marcus, it is important and motivating. – Sveinung Aug 31 at 14:53
1

Here are two solutions: one based on custmised \cmidrules that mimick \toprule and \bottomrule, and another based on blkarray, with a simpler sy,tax, and only 3 columns. Unfortunately, the latter package is not compatible with booktabs, so I had to play with \BAhhline to obtain thicker rules and the correct spacing at top and bottom.

\documentclass{article}

\usepackage{booktabs, bigdelim, rotating}%{
\newcommand{\mytoprule}{\noalign{\vskip -\aboverulesep}\cmidrule[\heavyrulewidth]{2-4}}
\newcommand{\mybottomrule}{\cmidrule[\heavyrulewidth]{2-4}\noalign{\vskip -\belowrulesep}}
\usepackage{blkarray, hhline}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{llcc}
\mytoprule
& header1 & header 2 & header 3 \\
\cmidrule{2-4}
\ldelim\{{4}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group1}}] & 1 & a & g \\
& 2 & b & h \\
& 3 & c & i \\
& 3 & c & i \\
\addlinespace[0.5ex]
\ldelim\{{6}{4mm}[\parbox{4mm}{\rotatebox[origin=c]{90}{group2}}] & 4 & d & j \\
& 5 & e & k \\
& 6 & f & l \\
& 7 & g & m \\
& 8 & h & n \\
& 9 & i & o \\
\mybottomrule
\end{tabular}
\end{table}

\begin{table}[htbp]
\centering
\doublerulesep =0.05pt
\begin{blockarray}{lcc}
\hhline{===}
\BAnoalign{\vskip -5.3ex}
 header1 & header 2 & header 3 \\
 \BAhline
\begin{block}{\Left{\rotatebox[origin=c]{90}{group1}\,}{\{\,}lcc}
 1 & a & g \\
 2 & b & h \\
 3 & c & i \\
 3 & c & i \\
\end{block}
\begin{block}{\Left{\rotatebox[origin=c]{90}{group2}\,}{\{\,}lcc}%
 4 & d & j \\
 5 & e & k \\
 6 & f & l \\
 7 & g & m \\
 8 & h & n \\
 9 & i & o \\%\
\end{block}
\BAnoalign{\vskip -5.3ex}
\hhline{===}
\end{blockarray}
\end{table}

\end{document}

enter image description here

  • thank you for your answer! I didn't do the custom commands myself but I was afraid that might be the best solution (see my question #1 comment). They look cool, thank you. – Marcus Aug 9 at 16:53
  • it is probably nice to use an argument for, e.g., mytoprule: \newcommand{\mytoprule}[1]{\noalign{\vskip -\aboverulesep}\cmidrule[\heavyrulewidth]{#1}}. This allows for calling it similar to \cmidrule like \mytoprule{2-4}. – Marcus Aug 9 at 16:56
  • 1
    I guess you're right. I just wanted to save the user the hassle to have to type the range of columns each time, but upon reflection there's little chance all tables will have the same number of columns. – Bernard Aug 9 at 18:04
  • @Bernard In addition option for spanning, an option for left,right` - trimming is necessary. Preferably with the same syntax with parentheses. Maybe it is possible to ask the maintainer to implement the syntax for toprule and \bottomrule. – Sveinung Aug 9 at 18: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.