I want to set a lightgray color behind my table, using colorbox. Following this solution, I created the following MWE:
\begin{table}[H]
\renewcommand{\arraystretch}{1.5}
\centering
\begingroup\setlength{\fboxsep}{0pt}
\colorbox{gray!50}{%
\begin{tabular}{ | c | c | c | c | c | c | }
\arrayrulecolor{black} %changes color of hline
\hline
& & \multicolumn{2}{c|}{\textbf{test test}} & \multicolumn{2}{c|}{\textbf{test test}} \\
\hhline{~|~|-|-|-|-|}
\multirow{-2}{*}{\textbf{\shortstack{teeest\\ teeeeeeest}}} & \multirow{-2}{*}{{\shortstack{\textbf{test}\\ \textbf{teeeest}\\(sec)}}} & (mW) & (hrs/days) & (mW) & (hrs/days) \\[0.6pt]
\hline
\textbf{test 1} & 8 & 16 & 64 & 2 & 2\\
\textbf{test 2} & 12 & 24 & 96 & 2 & 2\\
\textbf{test 3} & 14.4 & 28.8 & 115.2 & 2 & 2\\
\textbf{test 4} & 20 & 40 & 160 & 2 & 2 \\
\textbf{test 5} & 20 & 40 & 160 & 2 & 2\\
\hline
\end{tabular}
}\endgroup
\caption{test teest}
\end{table}
The output is this:
As you can see, the background is not exactly behind the tablular. In fact it seems that the tabular is also not centered after I add the background,ut the colorbox seems centered. Why is that?



\end{tabular}. – Ulrike Fischer Apr 26 '21 at 16:23