[Tex/LaTex] \rowcolor not shading properly

colortbltables

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
      \item This is where authors provide additional information about
      the data, including whatever notes are needed.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\end{document}

Best Answer

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
      \item This is where authors provide additional information about
      the data, including whatever notes are needed.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\end{document} 

enter image description here

Related Question