LaTeX: shaded headers and rows with booktabs

example

For my bachelor’s thesis, I spend some time convincing LaTeX to create tables in a fashion I like. One part of this adventure was changing the color of the horizontal rulers and shading both headers as well as selected rows. The screenshot gives an example how this looks like. Do not try to shade every second row as this looks rather ugly and is less legible – at least for me. Now here’s the code:

\definecolor{fu-blue}{RGB}{0, 51, 102} % blue text
\newcommand{\topline}{\arrayrulecolor{fu-blue}\specialrule{0.1em}{\abovetopsep}{0pt}\arrayrulecolor{fu-blue!20}\specialrule{\belowrulesep}{0pt}{0pt}\arrayrulecolor{fu-blue}}
\newcommand{\midline}{\arrayrulecolor{fu-blue!20}\specialrule{\aboverulesep}{0pt}{0pt}\arrayrulecolor{fu-blue}\specialrule{\lightrulewidth}{0pt}{0pt}\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}\arrayrulecolor{fu-blue}}
\newcommand{\rowmidlinec}{\arrayrulecolor{fu-blue!20}\specialrule{\aboverulesep}{0pt}{0pt}\arrayrulecolor{fu-blue}}
\newcommand{\headrow}{\rowcolor{fu-blue!20}[2pt][2pt]}
\newcommand{\shaderow}{\rowcolor{fu-blue!10}[2pt][2pt]}

% Now, you have to use slightly different commands for booktabs

\begin{table}
\caption{CAPTION/LABEL}
\begin{tabularx}{\columnwidth}{D{.}{}{2}D{.}{.}{3}D{.}{.}{2}D{.}{.}{5}D{.}{.}{7}lD{.}{.}{5}}
\topline 
\multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{$a$} & \multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{$E$} & \multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{$O$} &\multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{\texttt{limit}} &\multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{\texttt{boxsize}} &\multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{\texttt{stepdiv}} &\multicolumn{1}{>{\columncolor{fu-blue!20}[2pt][2pt]}l}{\texttt{stepsize}}\\\midline
5 & 15 & 91 & 6 & 0.46 & 4 & 0.058 \\
6 & 3 & 143 & 6 & 0.13 & 4 & 0.039\\
7 & 5 & 77 & 6 & 0.11 & 4 & 0.039 \\
\shaderow 8 &  1 & 1 & 10 &  1.1 & 4 & 0.038 \\
\shaderow 9 & 12 & 124 &\bf4 & 0.61 & 5 & 0.046\\
\shaderow 10 &  4 & 149 & 6 & 0.17 & 4 & 0.028\\
11 &  5 & 148 & 3 & 0.15 & 6 & 0.038 \\
12 & 2 & 115  & 6 &  0.17 & 5 &  0.031\\
13 & 2 & 158  & 10 & 0.12 & 4 & 0.028\\
\shaderow 14 & 2 & 911 & \bf3 & 0.15 & 7 & 0.030\\
\shaderow 15 &  17 & 651 & 14 & 0.44 & 3 &  \bf0.\bf018 \\
\shaderow 16 &  5 &\bf8 & 12 & 0.80 & 3 & \bf0.\bf018\\
17 & 15 &40 & 11 & 0.92 &  \bf4 & \bf0.\bf028 \\
18 & 24 & 203 & 11 & 0.092 & 3 &\bf0.\bf019\\
\hspace*{2.7pt}20 & 11 & 109 & 11 & 0.14 & 3 & \bf0.\bf019\\
\bottomrule
\end{tabularx}
\end{table}