# How to get same background color all over header in threeparttable

I am trying to get the entire header area (the two rows between \toprule and the long \midrule) of the table area to get the same background color (without any whitespace), but it doesn't seem to work. Any ideas on how this may be solved? Any way to set the ruler color as well?

I tried adding the \rowcolor{lightgray} twice, but that doesn't seem to have any effect.

The code I have so far (MWE):

\documentclass{article}

\usepackage[table]{xcolor}
\newcolumntype{s}{>{\columncolor[HTML]{AAACED}} p{3cm}}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{threeparttable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}

\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{dsfsdfsdfsdfdsfdfsdsf}
\label{tab:strnedbhendbidrmestnedb74000117}
\begin{tabular}{@{}p{0,40\textwidth}*{4}{L{\dimexpr0,18\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \rowcolor{lightgray} \multicolumn{2}{c}{\textbf \Longstack{dsfdfsdf}}  &
\rowcolor{lightgray} \multicolumn{2}{c}{\textbf \Longstack{sdfsdf}}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
$fsdfsdf$ & $ss_{d}$  &  $bf_{tot}$ & $rr_{dg}$  &  $gg_{tot}$ \\
\midrule
$Q_{rr}$ & 6,7 & 24 & 6,7 & 3  \\
jj & 6,7 & 14 & 2,2 & 3 \\
$r_{g}$ & 6,7 & 26 & -3,0 & -4 \\
$y_{tw}$ & 433,4 & 37 & 433,1 & 98 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}


This how it appears so far:

UPDATE

As per the comment of mhtsort I tried the following:

\toprule
\rowcolor{lightgray} &  \multicolumn{2}{c}{\textbf \Longstack{dsfdfsdf}} \rowcolor{lightgray} &
\multicolumn{2}{c}{\textbf \Longstack{sdfsdf}}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}


But it results in this, which doesn't solve the issue:

UPDATE 2: Adjusted as per the answer of Zarko. Also I added another \rowcolor{lightgray} to try and fill up all the area between two rows between \toprule and the long \midrule.

\begin{tabularx}{\linewidth}{X*{2}{S[table-format=3.1]S[table-format=2]} }% %
\toprule
\rowcolor{lightgray}
&   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\
\cmidrule(l){2-3}
\cmidrule(l){4-5}
\rowcolor{lightgray}
$fsdfsdf$   & {$ss_{d}$}    & {$bf_{tot}$}  & {$rr_{dg}$}   & {$gg_{tot}$}  \\ \midrule


However there is the some whitespace near the \cmidrule, \toprule and the \midrule as can be seen from the results here (whitespace here refers to the white area between the grey colored background and the \cmidrule, \toprule and the \midrule):

UPDATE 3: As per the last update Zarko this looks much better now. For the white artifacts there might be no solution.

• What do you call the ‘header area’? The area of the two rows between \toprule and the long \midrule? Or only he first row? – Bernard May 9 '18 at 22:18
• The two rows between \toprule and the long \midrule – jibo May 9 '18 at 22:24
• And what is the L column type? – Bernard May 9 '18 at 22:31
• Your code produces errors irrelevant to your question. Please post a working example. To color the whole row you should use \rowcolor{lightgray} before the ambersand(&) symbol. – mhtsort May 9 '18 at 22:45
• I updated the code now, thought that I had everything included. That code which is above works for me now without errors. – jibo May 10 '18 at 7:53

• with of table is bigger than text width (0.4\textwidth + 4*0.18\textwidth=1,12\textwidth)
• what is \Longstack?
• \rowcolor had not to be used inside of cells (for this is \cellcolor)
• better formatting of numbers and correct - sign you will obtain by use S columns from the package siunitx.
• it is not clear, why you need so wide first column
• it is not clear why you use threeparttable

with some changes of your code i obtain:

mwe:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{threeparttable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}   % not used
\newcolumntype{s}{>{\columncolor[HTML]{AAACED}} p{3cm}}     % not used

\begin{document}
\begin{table}[ht]
\centering
\sisetup{table-column-width=0.15\linewidth,
output-decimal-marker={,}
}
\begin{threeparttable}
\caption{dsfsdfsdfsdfdsfdfsdsf}
\label{tab:strnedbhendbidrmestnedb74000117}
\begin{tabularx}{\linewidth}{X*{2}{S[table-format=3.1]S[table-format=2]} }% % <--- changed
\toprule
\rowcolor{lightgray}
&   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\
\cmidrule(l){2-3}
\cmidrule(l){4-5}
$fsdfsdf$   & {$ss_{d}$}    & {$bf_{tot}$}  & {$rr_{dg}$}   & {$gg_{tot}$}  \\
\midrule
$Q_{rr}$   &   6,7         & 24            &   6,7         &  3            \\
jj          &   6,7         & 14            &   2,2         &  3            \\
$r_{g}$ &   6,7         & 26            &  -3,0         & -4            \\
$y_{tw}$ & 433,4         & 37            & 433,1         & 98            \\
\bottomrule
\end{tabularx}
\end{threeparttable}
\end{table}
\end{document}


edited (1):

• it's not clear what you mean by white lines:
• are this white space between rules and colored row? this is caused with features of rules from booktabs (it can be removed with use of \belowrulesep=0pt \aboverulesep=0pt, see mwe below).
• or very thin vertical lines visible in some pdf previewers? they are only artifact of viewers ...

edited (2):

• after editing question is now clear what is the problem ...
• mwe, which solve your problem (with dirty hack, solution is not general) is:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{threeparttable}

\begin{document}
\begin{table}[ht]
\centering
\sisetup{table-column-width=0.15\linewidth,
output-decimal-marker={,}
}
\begin{threeparttable}
\caption{dsfsdfsdfsdfdsfdfsdsf}
\label{tab:strnedbhendbidrmestnedb74000117}
\begin{tabularx}{\linewidth}{X
*{2}{S[table-format=3.1]S[table-format=2]} }% % <--- changed
\toprule
\rowcolor{lightgray}
&   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\[-\arrayrulewidth] % <--- move up the next row for line width
\cmidrule(l){2-3}
\cmidrule(l){4-5}
$fsdfsdf$   & {$ss_{d}$}    & {$bf_{tot}$}  & {$rr_{dg}$}   & {$gg_{tot}$}  \\
\midrule
$Q_{rr}$   &   6,7         & 24            &   6,7         &  3            \\
jj          &   6,7         & 14            &   2,2         &  3            \\
$r_{g}$ &   6,7         & 26            &  -3,0         & -4            \\
$y_{tw}$ & 433,4         & 37            & 433,1         & 98            \\
\bottomrule
\end{tabularx}
\end{threeparttable}
\end{table}
\end{document}


• This looks very good now, when I added grey background to However about the: "very thin vertical lines visible in some pdf previewers? they are only artifact of viewers ...". Will these artifacts be shown when printed on paper? Is there a way to make sure this is avoided during printing? – jibo May 10 '18 at 10:13
• @jibo, see edited answer. i hope that now it solve your problem. – Zarko May 10 '18 at 12:17
• Looks very good now. – jibo May 10 '18 at 21:47