Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

booktabs: how to fill space between toprule and midrule with color?

1,388 views
Skip to first unread message

Alexander Lembach

unread,
Aug 25, 2009, 2:51:01 AM8/25/09
to
Hello. To typeset tables in my document, I use the package "booktabs"
and also the package "xcolor" (with the "table" option) to use colors.
How can I fully fill the space between the \toprule and the next
\midrule? When I do the following, some white space below the toprule
and above the midrule still remains.

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{ll}
\toprule\rowcolor{gray}Head1 & Head2\\ % <-- Should have gray
background
\midrule
A & B\\
\bottomrule
\end{tabular}
\end{document}

Any help is much appreciated!

Marc van Dongen

unread,
Aug 25, 2009, 8:28:02 AM8/25/09
to
On Aug 25, 7:51 am, Alexander Lembach <al...@gmx.de> wrote:

> [ problem with booktabs and xcolor ]

When I opened the booktabs manual I noticed there was a \specialrule
command which requires the width of the rule you want to typeset.
Reading a bit further, I found that there were also commands for the
default widths of the different rules. Putting it all together I got
the following.

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{ll}

\specialrule{\heavyrulewidth}{0pt}{0pt}
\rowcolor{gray}Head1 & Head2\\ % <-- Should has gray background
\specialrule{\lightrulewidth}{0pt}{0pt}


A & B\\
\bottomrule
\end{tabular}
\end{document}

Regards,


Marc van Dongen

Alexander Lembach

unread,
Aug 25, 2009, 12:22:43 PM8/25/09
to
Thank you Marc! Though this doesn't exactly do what I need (the vspace
after the toprule and before and after the midrule is too small), this
was a good advice since I can make that space via appropriately
colored specialrule, like this:

\begin{tabular}{ll}
\specialrule{\heavyrulewidth}{0pt}{0pt}

\arrayrulecolor{red}
\specialrule{\belowrulesep}{0pt}{0pt}
\rowcolor{red}Head1 & Head2\\
\specialrule{\aboverulesep}{0pt}{0pt}
\arrayrulecolor{black}
\specialrule{\lightrulewidth}{0pt}{0pt}
\arrayrulecolor{white}
\specialrule{\belowrulesep}{0pt}{0pt}
\arrayrulecolor{black}


A & B\\
\bottomrule
\end{tabular}

Now I just have to learn how to define an environment that would
automatically prepend this to all tables! :-)

Dan Luecking

unread,
Aug 26, 2009, 1:29:21 PM8/26/09
to

\renewcommand{\arraystretch}{1.4} works well with your table
(without the extra red and white rules). It would not be so
good if the table contained taller material.

Some folks manage the separation between rules and text by
inserting empty rows (in the appropriate color). such rows
would have to contain something invisible with a little
height to produce the separation.


Dan
To reply by email, change LookInSig to luecking

Dan Luecking

unread,
Aug 27, 2009, 12:53:52 PM8/27/09
to
On Wed, 26 Aug 2009 12:29:21 -0500, Dan Luecking <Look...@uark.edu>
wrote:

>On Tue, 25 Aug 2009 09:22:43 -0700 (PDT), Alexander Lembach
><al...@gmx.de> wrote:
>
>>Thank you Marc! Though this doesn't exactly do what I need (the vspace
>>after the toprule and before and after the midrule is too small), this
>>was a good advice since I can make that space via appropriately
>>colored specialrule, like this:

...


>
>Some folks manage the separation between rules and text by
>inserting empty rows (in the appropriate color). such rows
>would have to contain something invisible with a little
>height to produce the separation.

Oops. I was partly in plain TeX mode when I wrote that.
I forgot that LaTeX puts a strut on each line, empty or
not. So an empty line is way too much space. There is
probably some internal command (\@arstrut) one can
modify to get around that (or some package that will do
it for you, but that is beyond my knowledge. (Although
a cellspace package has appeared recently that might
have some relevance.)

0 new messages