1

I want to get the background colors of my table similar to this table, but not sure how to change the text to white and the background of the top column and rows to black. enter image description here

Ive used the following code so far:

  \documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{multirow, booktabs}
\usepackage[dvipsnames,table]{xcolor}

\begin{document}

\begin{tabular}{|l c c c c c c c|}
\hline
\rowcolor{SeaGreen}\multicolumn{4}{|c}{\textbf{ESS3}} & \multicolumn{4}{c|}{\textbf{ESS5}} \\
\rowcolor{SeaGreen}
    \textbf{Utfall} & \textbf{Kontroll} & \textbf{Behandling} & \textbf{Diff} & \textbf{Kontroll} &  \textbf{Behandling} & \textbf{Diff}&  \textbf{DiD}            \\

\hline
\multicolumn{8}{|l|}{\textbf{Panel A: No controls}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ [1ex]

\multicolumn{8}{|l|}{\textbf{Panel B: Controlling for individual characteristics}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ [1ex]

\multicolumn{8}{|l|}{\textbf{Panel C: Controlling for individual characteristics}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ [1ex]

\multicolumn{8}{|l|}{\textbf{Panel D: Controlling for individual characteristics}}\\ [1ex]
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ [1ex]
\hline
\end{tabular}

which yields the following output:

enter image description here

So I want the layout of the table to be the same as the table I already made, but I don't know how to change the background color and text color. I also want the white lines in the top part of the table to be removed but not sure how to go about this. Any help would be appreciated.

  • Welcome to TeX SX! Do you have any caption? And should it be on a black background? – Bernard Mar 13 at 16:15
  • Haven't included any caption yet. I want the upper part of the table to be black with white coloring and the lower part to be blue greyish with black text, if that answered your question. – Hammer0903 Mar 13 at 16:41
1

Here is a simple solution with \colorbox and \rowcolor:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{multirow, booktabs}
\usepackage[dvipsnames,svgnames, table]{xcolor}
\newcommand{\textbw}[1]{\bfseries\color{white}#1}
\setlength{\extrarowheight}{2pt}

\begin{document}

{\setlength{\fboxsep}{0pt}
    \colorbox{LightSteelBlue}{%
    \begin{tabular}{|l*{7}{c}|}
    \hline
    \rowcolor{DarkSlateGrey}\multicolumn{4}{c|}{\textbw{ESS3}} & \multicolumn{4}{c|}{\textbw{ESS5}} \\
    \rowcolor{DarkSlateGrey} \textbw{Utfall} & \textbw{Kontroll} & \textbw{Behandling} & \textbw{Diff} & \textbw{Kontroll} & \textbw{Behandling} & \textbw{Diff}& \textbw{DiD} \\

    \hline
    \multicolumn{8}{|l|}{\textbf{Panel A: No controls}}\\
    \textbf{Coef} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\
    \textbf{t-statistics} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\ [1ex]

    \multicolumn{8}{|l|}{\textbf{Panel B: Controlling for individual characteristics}}\\
    \textbf{Coef} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\
    \textbf{t-statistics} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\ [1ex]

    \multicolumn{8}{|l|}{\textbf{Panel C: Controlling for individual characteristics}}\\
    \textbf{Coef} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\
    \textbf{t-statistics} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\ [1ex]

    \multicolumn{8}{|l|}{\textbf{Panel D: Controlling for individual characteristics}}\\ [1ex]
    \textbf{Coef} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\
    \textbf{t-statistics} & 0.075 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 & 0.091 \\ [1ex]
    \hline
    \end{tabular}}%
}
 \end{document} 

enter image description here

1

Here is a possibility on how to achieve a white caption on a black background. I have also used the rules from the booktabs package.

The idea to use a colorbox in order to make the background of the rest of the table blue, is borrowed from Bernard's answer

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{multirow, booktabs}
\usepackage[dvipsnames, svgnames, table]{xcolor}
\usepackage{tabularx}
\usepackage{caption}
\DeclareCaptionFormat{mycaptionformat}{%
  \colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{#1#2\color{white}\bfseries#3}}
} 
\captionsetup[table]{format=mycaptionformat,font={color=white,bf},skip=0pt}

\begin{document}

\begin{table}
\caption{my caption}
\setlength{\fboxsep}{0pt}
\colorbox{LightSteelBlue}{%
\begin{tabularx}{\textwidth}{X c c c c c c c}
\toprule
& \multicolumn{3}{c}{\textbf{ESS3}} & \multicolumn{3}{c}{\textbf{ESS5}} & \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7}
    \textbf{Utfall} & \textbf{Kontroll} & \textbf{Behandling} & \textbf{Diff} & \textbf{Kontroll} &  \textbf{Behandling} & \textbf{Diff}&  \textbf{DiD}            \\

\midrule
\multicolumn{8}{l}{\textbf{Panel A: No controls}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ \addlinespace

\multicolumn{8}{l}{\textbf{Panel B: Controlling for individual characteristics}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ \addlinespace

\multicolumn{8}{l}{\textbf{Panel C: Controlling for individual characteristics}}\\
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ \addlinespace

\multicolumn{8}{l}{\textbf{Panel D: Controlling for individual characteristics}}\\ [1ex]
\textbf{Coef}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\
\textbf{t-statistics}   &   0.075  &    0.091   &   0.091   &   0.091   &   0.091 &   0.091   &   0.091 \\ 
\bottomrule
\end{tabularx}}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.