3

I'm trying to make an ENTIRE table gray (see picture enter image description here

but I can't get it to work with \raisebox.

Here's my code:

\documentclass[a4paper,11pt]{article}
\usepackage{color,amsmath,amsfonts,amssymb}
\usepackage{rotating}
\usepackage{colortbl}

\definecolor{Gray}{gray}{0.9}

\newcolumntype{g}{>{\columncolor{Gray}}c}
\begin{table}[h]
\begin{center} {\footnotesize
\begin{tabular}{lccg}
\hline
 & \multicolumn{3}{c}{AFC Window 1}    \\
  & \multicolumn{1}{c}{gmt} & \multicolumn{1}{c}{jfk} &
\multicolumn{1}{c}{fbi}\\\hline
\rowcolor{Gray}
& $0.025^*$ & -0.002 & $1.155^*$ \\[-2ex]
\rowcolor{Gray}
\raisebox{2ex}{Constant} & (1.22) & (2.22) & (0.56)\\[0ex]
& $0.025^*$ & -0.002 & $1.155^*$ \\[-2ex]
\raisebox{2ex}{Constant} & (1.22) & (2.22) & (0.56)\\[0ex]
& $0.025^*$ & -0.002 & $1.155^*$ \\[-2ex]
\raisebox{2ex}{Log(assets)$^a$} & (1.22) & (2.22) & (0.56)\\[0ex]
\hline
\end{tabular} }
\end{center}
\caption{\footnotesize Number of turns and distance between top and bottom.}
\label{turns}
\end{table}


\end{document}

Thanks guys.

David Carlisle
  • 757,742
  • It's not clear what layout you want to achieve. You have negative spacing between the rows, so the coloured panel of one row obscures the text in the previous row. From your title, if you really want a background to the whole table don't use \rowcolor at all just use \colorbox{Gray}{\begin{tabular}..... – David Carlisle Jul 13 '12 at 15:40

2 Answers2

3

You have to "smash" the raised box, rather than using negative vertical space

\documentclass[a4paper,11pt]{article}
\usepackage{color,amsmath,amsfonts,amssymb}
\usepackage{rotating}
\usepackage{colortbl}

\definecolor{Gray}{gray}{0.9}

\begin{document}
\begin{table}[h]
\centering\footnotesize
\begin{tabular}{l*{2}{>{$}c<{$}}>{\columncolor{Gray}$}c<{$}}
\hline
& \multicolumn{3}{c}{AFC Window 1}    \\
& \multicolumn{1}{c}{gmt} & \multicolumn{1}{c}{jfk} &
\multicolumn{1}{c}{fbi}\\\hline
\rowcolor{Gray}%
& 0.025^* & -0.002 & 1.155^* \\
\rowcolor{Gray}%
\smash{\raisebox{1.5ex}{Constant}}& (1.22) & (2.22) & (0.56)\\
& 0.025^* & -0.002 & 1.155^* \\
\smash{\raisebox{1.5ex}{Constant}}& (1.22) & (2.22) & (0.56)\\
& 0.025^* & -0.002 & 1.155^* \\
\smash{\raisebox{1.5ex}{Log(assets)\textsuperscript{\itshape a}}}& (1.22) & (2.22) & (0.56)\\
\hline
\end{tabular}
\caption{Number of turns and distance between top and bottom.}
\label{turns}
\end{table}


\end{document}

I've made also some other improvements, so that the minus signs appear as they should.

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
1

For information, here is a way to construct that table with {NiceTabular} of nicematrix.

\documentclass[a4paper,11pt]{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}

\begin{table}[h] \centering\footnotesize

\begin{NiceTabular}{lccc} \CodeBefore \rowcolor[gray]{0.9}{3,4} \rectanglecolor[gray]{0.9}{3-4}{8-4} \Body \toprule & \Block{1-3}{AFC Window 1} \ & gmt & jfk & fbi \ \midrule \Block{2-1}{Constant} & $0.025^$ & $-0.002$ & $1.155^$ \ & $(1.22)$ & $(2.22)$ & $(0.56)$ \ \Block{2-1}{Constant} & $0.025^$ & $-0.002$ & $1.155^$ \ & $(1.22)$ & $(2.22)$ & $(0.56)$ \ \Block{2-1}{Log(assets)\textsuperscript{\itshape a}} & $0.025^$ & $-0.002$ & $1.155^$ \ & $(1.22)$ & $(2.22)$ & $(0.56)$ \ \bottomrule \end{NiceTabular}

\caption{Number of turns and distance between top and bottom.} \label{turns} \end{table}

\end{document}

You need several compilations.

Ouput of the above code

F. Pantigny
  • 40,250