Title: How to get same background color all over header in threeparttable
Tags: tables;color;threeparttable
Question: 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}{&gt;{\columncolor[HTML]{AAACED}} p{3cm}}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{threeparttable}
\newcolumntype{L}[1]{&gt;{\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
&amp; \rowcolor{lightgray} \multicolumn{2}{c}{\textbf \Longstack{dsfdfsdf}}  &amp;
\rowcolor{lightgray} \multicolumn{2}{c}{\textbf \Longstack{sdfsdf}}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
$fsdfsdf$ &amp; $ss_{d}$  &amp;$ $  $bf_{tot}$ &amp; $rr_{dg}$  &amp; $  $ $gg_{tot} $ \\
\midrule
$Q_{rr} $ &amp; 6,7 &amp; 24 &amp; 6,7 &amp; 3  \\
jj &amp; 6,7 &amp; 14 &amp; 2,2 &amp; 3 \\
$  r_{g}  $ &amp; 6,7 &amp; 26 &amp; -3,0 &amp; -4 \\
$   y_{tw}$ &amp; 433,4 &amp; 37 &amp; 433,1 &amp; 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} &amp;  \multicolumn{2}{c}{\textbf \Longstack{dsfdfsdf}} \rowcolor{lightgray} &amp;
\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}
&amp;   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&amp;   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\
\cmidrule(l){2-3}
\cmidrule(l){4-5}
\rowcolor{lightgray}
$fsdfsdf$   &amp; {$ss_{d}$}    &amp; {$bf_{tot}$}  &amp; {$rr_{dg}$}   &amp; {$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.
Comment: What do you call the ‘header area’? The area of the two rows between \toprule and the long \midrule? Or only he first row?

Comment: And what is the `L` column type?

Comment: 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.

Comment: The two rows between \toprule and the long \midrule

Comment: I updated the code now, thought that I had everything included. That code which is above works for me now without errors.

Here is the accepted answer: your table has many issues:
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:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{threeparttable}
\newcolumntype{L}[1]{&gt;{\raggedright\arraybackslash}p{#1}}   % not used
\newcolumntype{s}{&gt;{\columncolor[HTML]{AAACED}} p{3cm}}     % not used
\usepackage{siunitx}    % <--- added
\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}
&amp;   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&amp;   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\
\cmidrule(l){2-3}
\cmidrule(l){4-5}
$fsdfsdf$   &amp; {$ss_{d}$}    &amp; {$bf_{tot}$}  &amp; {$rr_{dg}$}   &amp; {$gg_{tot}$}  \\
\midrule
$Q_{rr} $   &amp;   6,7         &amp; 24            &amp;   6,7         &amp;  3            \\
jj          &amp;   6,7         &amp; 14            &amp;   2,2         &amp;  3            \\
$  r_{g}  $ &amp;   6,7         &amp; 26            &amp;  -3,0         &amp; -4            \\
$   y_{tw}$ &amp; 433,4         &amp; 37            &amp; 433,1         &amp; 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}
\usepackage{siunitx}            % <--- added
\begin{document}
\begin{table}[ht]
\centering
\sisetup{table-column-width=0.15\linewidth,
output-decimal-marker={,}
}
\renewcommand\arraystretch{1.2} % <--- added
\belowrulesep=0pt               % <--- added
\aboverulesep=0pt               % <--- added
\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}
&amp;   \multicolumn{2}{c}{\textbf{dsfdfsdf}}
&amp;   \multicolumn{2}{c}{\textbf{sdfsdf}}                     \\[-\arrayrulewidth] % <--- move up the next row for line width
\cmidrule(l){2-3}
\cmidrule(l){4-5}
$fsdfsdf$   &amp; {$ss_{d}$}    &amp; {$bf_{tot}$}  &amp; {$rr_{dg}$}   &amp; {$gg_{tot}$}  \\
\midrule
$Q_{rr} $   &amp;   6,7         &amp; 24            &amp;   6,7         &amp;  3            \\
jj          &amp;   6,7         &amp; 14            &amp;   2,2         &amp;  3            \\
$  r_{g}  $ &amp;   6,7         &amp; 26            &amp;  -3,0         &amp; -4            \\
$   y_{tw}$ &amp; 433,4         &amp; 37            &amp; 433,1         &amp; 98            \\
\bottomrule
\end{tabularx}
\end{threeparttable}
\end{table}
\end{document}
Comment for this answer: @jibo, see edited answer. i hope that now it solve your problem.
Comment for this answer: 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?
Comment for this answer: Looks very good now.


{'source': 'StackExchangeDataset', 'subset': 'tex.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:05/09/18', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<tables><color><threeparttable>', 'Title': 'How to get same background color all over header in threeparttable', 'ViewCount': 230, 'id': 430886, 'user_AboutMe': None, 'user_AccountId': 5062631.0, 'user_DisplayName': 'jibo', 'user_Reputation': 135.0, 'user_Views': 7.0, 'user_id': 153040.0}}