I am using this template for making tables. I tried to add \rowcolor[gray]{.8} between \toprules and \midrules but the the effect is bad in the sense that it highlight on 3/4 of the row leaving the edges white.

Any solution?

\documentclass{article}
\usepackage{colortbl, xcolor}
\usepackage{booktabs,caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\begin{document}
\definecolor{lightgray}{rgb}{.9,.9,.9}
\begin{table}
\begin{threeparttable}
\caption{Sample ANOVA table}
\begin{tabular}{lllll}
\toprule
Stubhead & $$df$$ & $$f$$ & $$\eta$$ & $$p$$ \\
\midrule
Row 1    & 1        & 0.67    & 0.55       & 0.41    \\
Row 2    & 2        & 0.02    & 0.01       & 0.39    \\
Row 3    & 3        & 0.15    & 0.33       & 0.34    \\
Row 4    & 4        & 1.00    & 0.76       & 0.54    \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
the data, including whatever notes are needed.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

• At the beginning of the post there is an "Hi All,". Just wanted to point it out. It is the second time that this happens and it honestly looks like a big impolite. – user1463152 Jul 10 '14 at 19:40
• Greetings and thanks are assumed: we're quite a friendly community and we trust in newcomers to be as friendly as everybody here. We believe it's simpler to directly state the problem; the better way to thank is upvoting useful answers and accepting the most useful one, provided it solves the problem or leads to a full solution. – egreg Jul 10 '14 at 19:59

I think the problem comes from booktabs, which adds some vertical space above and below its rules. This vertical space seems not to be considered as part of the row cells, and hence is not coloured.

A workaround consists in using the cellspace package, which defines a minimal vertical vertical space between the top of a row and the above \hline and symmetrically a minimal vertical space between the bottom of a row and the below \hline. This has more or less the same effect as \addlinespace from booktabs, but is taken into consideration when colouring the cells.

Another feature of booktabs, namely horizontal rules of different thicknesses, can be achieved with the makecell package, which has an \Xhline{thickness} command. So I defined a \thickhline command, that has the same thickness as the default for \top/\bottomrules in booktabs (0.08em).

Here is a code:

\documentclass{article}
\usepackage{colortbl, xcolor}
\usepackage{booktabs,caption,fixltx2e}
\usepackage[flushleft]{threeparttable}

\usepackage{cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}

\usepackage{makecell}
\newcommand\thickhline{\Xhline{0.08em}}

\begin{document}
\definecolor{lightgray}{rgb}{.9,.9,.9}
\begin{table}[!ht]
\begin{threeparttable}
\caption{Sample ANOVA table}
\begin{tabular}{*{6}{Sl}}
%\toprule
\thickhline
\rowcolor[gray]{.8} Stubhead & $$df$$ & $$f$$ & $$\eta$$ & $$p$$ \\
\hline
Row 1 & 1 & 0.67 & 0.55 & 0.41 \\
Row 2 & 2 & 0.02 & 0.01 & 0.39 \\
Row 3 & 3 & 0.15 & 0.33 & 0.34 \\
Row 4 & 4 & 1.00 & 0.76 & 0.54 \\
\thickhline
\end{tabular}\smallskip
\begin{tablenotes}
\small
the data, including whatever notes are needed.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}


• You can use features of \booktabs, for instance \specialrule{\heavyrulewidth}{0pt}{0pt}. – egreg Jul 10 '14 at 20:15
• But then you don't have any vertical space added, I guess? Which makes ugly tables. – Bernard Jul 10 '14 at 20:18
• The second and third arguments are for spaces above and below the rule, respectively. My advice is not shading the table header, the heavier rules already show it clearly. – egreg Jul 10 '14 at 20:19
• @egreg: That's another question. The problem remains if you have, say, a table with many rows and want to alternate colours in rows. – Bernard Jul 10 '14 at 20:34
• That's a different problem; but in that case the shading need not touch the rules. – egreg Jul 10 '14 at 20:38

Similar to @Bernard answer ... Difference are in use of packages boldline and treepartablex. Instead of packages colortbl and xcolor is used only xcolor with option table. Also it is declared only five columns as they are used in table:

\documentclass{article}
\usepackage[table]{xcolor}
\definecolor{lightgray}{rgb}{.9,.9,.9}
\usepackage{caption}
\usepackage{boldline, cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage[referable,flushleft]{threeparttablex}

\begin{document}
\begin{table}[!ht]
\begin{threeparttable}
\caption{Sample ANOVA table}
\label{tab:my table}
\begin{tabular}{*{5}{Sl}}
\hlineB{2}
\rowcolor[gray]{.8} Stubhead & $$df$$ & $$f$$ & $$\eta$$ & $$p$$ \\
\hlineB{1.5}
Row 1 & 1 & 0.67 & 0.55 & 0.41 \\
Row 2 & 2 & 0.02 & 0.01 & 0.39 \\
Row 3 & 3 & 0.15 & 0.33 & 0.34 \\
Row 4 & 4 & 1.00 & 0.76 & 0.54 \\
\hlineB{2}
\end{tabular}
\begin{tablenotes}\footnotesize