# Color a table with toprule and cmidrule [duplicate]

I have created a table in the following way:

\documentclass{article}
\usepackage[table,xcdraw]{xcolor} %Tables
\usepackage{array,multirow}
\usepackage{booktabs}

\begin{document}
\begin{table}\centering
\begin{tabular}{>{\columncolor[HTML]{EFEFEF}}l>{\columncolor[HTML]
{EFEFEF}}l>{\columncolor[HTML]{EFEFEF}}l>{\columncolor[HTML]{EFEFEF}}l>
{\columncolor[HTML]{EFEFEF}}l>{\columncolor[HTML]{EFEFEF}}l>
{\columncolor[HTML]{EFEFEF}}l>{\columncolor[HTML]{EFEFEF}}l}
\toprule
&  \multicolumn{3}{c}{\cellcolor[HTML]{EFEFEF}\textbf{Estimates}} &
&\multicolumn{3}{c}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]
{@{}l@{}}$\varepsilon$ s. d. and\\ correlation\end{tabular}}} \\\cmidrule{2-
4}\cmidrule{6-8}
& $\hat{b},\hat{\phi}$ & $\sigma(\hat{b})$ & implied&  & $r$ & $\Delta d$ &
$dp$ \\
\midrule
$r$  & 0.32324 & 2 & & & & &\\
$\Delta d$  & 0.32324 & 2 & & & & &\\
$dp$  & 0.32324 & 2 & & & & &\\

\bottomrule
\end{tabular}
\caption{Test}
\end{table}
\end{document}


And the problem is that not everything is filled in the color. It comes without everything being colored:

## marked as duplicate by JouleV, Stefan Pinnow, Kurt, Marijn, marmotApr 23 at 15:23

If you are just looking for a uniform bg color, then this seems a lot easier. I removed the column and cell colors, and wraped the entire table ina colored background. The \fboxsep to zero is to make the colored box go to the edge.

\documentclass{article}
\usepackage[table,xcdraw]{xcolor} %Tables
\usepackage{array,multirow}
\usepackage{booktabs}
\definecolor{mycolor}{HTML}{EFEFEF}
\begin{document}
\begin{table}\centering
\setlength{\fboxsep}{0pt}
\colorbox{mycolor}{\begin{tabular}{llllllll}
\toprule
&  \multicolumn{3}{c}{\textbf{Estimates}} &
&\multicolumn{3}{c}{\textbf{\begin{tabular}[c]
{@{}l@{}}$\varepsilon$ s. d. and\\ correlation\end{tabular}}} \\\cmidrule{2-
4}\cmidrule{6-8}
& $\hat{b},\hat{\phi}$ & $\sigma(\hat{b})$ & implied&  & $r$ & $\Delta d$ &
$dp$ \\
\midrule
$r$  & 0.32324 & 2 & & & & &\\
$\Delta d$  & 0.32324 & 2 & & & & &\\
$dp$  & 0.32324 & 2 & & & & &\\

\bottomrule
\end{tabular}}
\caption{Test}
\end{table}
\end{document}

• Can you use this construct with longtables? – Bernard Apr 23 at 12:09
• @Bernard as longtable supports line breaks and colorbox does not, no. But then I'd probably just have a look at the tcolorbox package, it should probably be able to do something similar – daleif Apr 23 at 12:11
• Yeap, just wanted to color everything. Your code worked exactly as I wanted, thanks. – Jennifer Apr 23 at 12:33