Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have created a rather complicated table with some columns that I want to color. For the table, I chose the booktabs and tabularx packages. For coloring the columns, I use colortbl.

The problem that I have is that \midrules show a white space, and the result does not please me at all. Here is a MWE:

\documentclass[a5paper]{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,tabularx}
\begin{document}
\pagestyle{empty}
\begin{table*}[!htb]
  \centering
  \begin{tabularx}{4cm}{>{\columncolor{gray}}cX>{\columncolor{gray}}c}
    \toprule
    1&2&3\\
    \midrule
    one&two&three\\
    one&two&three\\
    \cmidrule{2-3}
    one&two&three\\
    \midrule
    un&deux&trois\\
    \bottomrule
  \end{tabularx}
  \caption{caption}
\end{table*}
\end{document}

latex result

Looking around I found that booktabs supports colortbl in its latest version. However, it seems that it only supports colored horizontal lines.

I tried not using booktabs and replacing midrules for hlines. My huge table looks too crowded (once you booktab, you never go back, I guess).

My question is: is it possible to achieve a correct coloring in midrules ? Since I fear that the response is no: what low-cost recommendation do you have in order to color the columns of my table?

(When I say low-cost, I mean that I do not want to re-write my table contents)

share|improve this question
5  
from typographers view it makes no sense to have lines and colored cells –  Herbert Feb 16 '11 at 11:07

1 Answer 1

up vote 12 down vote accepted

There's no way to do this given the way booktabs inserts space between above and below its rules. As Herbert notes inthe comments, it's not clear that rules and colours are really a logical combination. So probably the best you can do is to increase the row height and set the space above and below the rules to 0.

\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,tabularx}

\begin{document}
% Your original table
  \begin{tabularx}{4cm}{>{\columncolor{gray}}cX>{\columncolor{gray}}c}
    \toprule
    1&2&3\\
    \midrule
    one&two&three\\
    one&two&three\\
    \cmidrule{2-3}
    one&two&three\\
    \midrule
    un&deux&trois\\
    \bottomrule
  \end{tabularx}
% same table with booktab rules but no above space and making rows bigger
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\extrarowheight}{.75ex}
  \begin{tabularx}{4cm}{>{\columncolor{gray}}cX>{\columncolor{gray}}c}
    \toprule
    1&2&3\\
    \midrule
    one&two&three\\
    one&two&three\\
    \cmidrule{2-3}
    one&two&three\\
    \midrule
    un&deux&trois\\
    \bottomrule
  \end{tabularx}
% same table without booktab rules
\setlength{\extrarowheight}{.75ex}
  \begin{tabularx}{4cm}{>{\columncolor{gray}}cX>{\columncolor{gray}}c}
    \hline
    1&2&3\\
    \hline
    one&two&three\\
    one&two&three\\
    \cline{2-3}
    one&two&three\\
    \hline
    un&deux&trois\\
    \hline
  \end{tabularx}
\end{document}

The middle table still looks marginally better than the third one.

three tables

share|improve this answer
    
Excellent @Alan, I think I am going to go for the second choice. One follow-up question: should I re-establish the modified lengths after the table? –  YuppieNetworking Feb 16 '11 at 13:51
    
Nevermind, I modified the lengths inside the table* environment and it works great. Thanks again. –  YuppieNetworking Feb 16 '11 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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