[Tex/LaTex] Color entire table

colortables

How do I get an entire table to get a background color. I dont mean the indivual cells but the entire table to get a gray shade. Something like this:

http://img818.imageshack.us/img818/8684/38613229.png

Best Answer

I'd simply put the tabular inside a \colorbox:

\documentclass{article}
\usepackage{booktabs,xcolor,siunitx}
\definecolor{lightgray}{gray}{0.9}

\begin{document}
\begingroup\setlength{\fboxsep}{0pt}
\colorbox{lightgray}{%
  \begin{tabular}{l*{4}{S[table-format=3.2]}@{}}
  \toprule
  Method & \multicolumn{4}{c}{Recognition rate (\%) vs.\ illumination} \\
  \cmidrule{2-5}
  & \multicolumn{1}{c}{Subset 2} &
    \multicolumn{1}{c}{Subset 3} &
    \multicolumn{1}{c}{Subset 4} &
    \multicolumn{1}{c}{Subset 5} \\
  \midrule
  Linear subspace [9]  & 100.00 & 100.00 &  85.00 &  {n/a} \\
  Cones-attached [9]   & 100.00 & 100.00 &  91.40 &  {n/a} \\
  Cones-cast [9]       & 100.00 & 100.00 & 100.00 &  {n/a} \\
  PCA                  &  98.33 &  79.17 &  30.00 &  15.79 \\
  LTV${}+{}$PCA        & 100.00 &  99.17 &  96.43 &  92.11 \\
  Our method${}+{}$PCA & 100.00 & 100.00 & 100.00 & 100.00 \\
  \bottomrule
  \end{tabular}%
}\endgroup
\end{document}

The local setting of \fboxsep is needed to avoid padding.

enter image description here

Related Question