[Tex/LaTex] Coloring columns in a table with colortbl and booktabs

booktabscolortables

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)

Best Answer

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