I don't really know how to make tables with booktabs
and other posts on this don't seem to help me too much.
I have to make a table similar to the one with the image below. How would I get on with something like this?
booktabs
I don't really know how to make tables with booktabs
and other posts on this don't seem to help me too much.
I have to make a table similar to the one with the image below. How would I get on with something like this?
\cellcolor
adds padding to ensure adjacent cell backgrounds are touching each other. I believe you don't need \cellcolor
at all.
\documentclass{article}
\usepackage{booktabs}
\usepackage{xcolor}
\makeatletter
\newcommand{\ccell}[3][]{%
\kern-\fboxsep
\if\relax\detokenize{#1}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\colorbox{#2}}%
{\colorbox[#1]{#2}}%
{#3}\kern-\fboxsep
}
\makeatother
\definecolor{cellgray}{gray}{0.9}
\AtBeginDocument{\setlength{\cmidrulekern}{0.3em}}
\begin{document}
\begin{tabular}{ccccc}
\toprule
\multicolumn{2}{c}{a} & \multicolumn{3}{c}{b} \\
\cmidrule(lr){1-2}\cmidrule(lr){3-5}
1 & 2 & \ccell[gray]{0.9}{3} & 4 & 5 \\
1 & 2 & \ccell{cellgray}{3} & 4 & 5 \\
\bottomrule
\end{tabular}
\end{document}
The two \kern
commands make TeX thinking the default padding of \colorbox
has not been added to the cell's width. Changing a bit the amount of trimming from \cmidrule
ensures the mid rules cover the colored cell.
Note that the syntax of \ccell
allows for directly specifying a color or also using a defined color.
The definition of \ccell
can be simplified into
\makeatletter
\protected\def\ccell#1#{%
\kern-\fboxsep
\@ccell{#1}%
}
\def\@ccell#1#2#3{%
\colorbox#1{#2}{#3}%
\kern-\fboxsep
}
\makeatother
Here is a rather different way of presenting the information which may or may not be suitable. Unlike the modified table, this fits within the confines of the text area. (The other produces overfull boxes.)
This is essentially a forest
tree, as justtrees
is an experimental wrapper for forest
. This may make it unacceptable for submission purposes, but you can include the code, if necessary, and load forest
directly instead. There is a copy of justtrees.sty
around somewhere but ask me for version 0.04 if you actually want to try this out.
\documentclass[11pt]{article}
\usepackage[margin=0.75in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{rotating,lmodern,justtrees}% version 0.04 of justtrees
\usetikzlibrary{calc,decorations.pathreplacing}
\begin{document}
\thispagestyle{empty}
\begin{sidewaysfigure}
\caption{\textbf{Summary of the modeling approaches included in the evaluation}}\label{fig2}% it would be better to use \captionsetup to format captions globally
\begin{center}
\begin{justtree}{
right justifiers,
for tree={
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label};
},
just format={font=\bfseries},
l sep+=5pt,
s sep+=5pt,
if n children=3{
calign child=2,
calign=child
}{},
if level=3{font=\itshape}{},
if level=5{math content}{},
},
}
[Modelling Approaches,
[{Frequentist ($l_{1}, l_{2}$ penalties)}, just=Paradigm
[{quadrupen, glmnet}, just=R Package
[None, just=Model Space Construction
[\lambda_{ENC}
[ENC,
tikz={
\draw (.south) |- ($(.south)!1/2!(iv2.south) - (10pt,35pt)$) coordinate (a) -- ++(0,-15pt) coordinate (b) ++(10pt,0) node (iv) [anchor=north] {Influential variables};
\draw (!>.south) |- ([xshift=10pt, yshift=10pt]a) -- ([xshift=10pt]b);
\draw (iv2.south) |- ([xshift=20pt]a) -- ([xshift=20pt]b);
\node [anchor=mid west, justifier format] at (right just 2.mid west |- iv.mid) {Output};
}
]
]
]
[Subsampling
[\lambda_{MB}
[PS
]
]
[\lambda_{ENC}
[LS,
tikz={
\draw (.south) |- ($(.south)!1/2!(ip2.south) - (25pt,25pt)$) coordinate (c) -- ++(0,-25pt) coordinate (d) ++(25pt,0) node (ip) [anchor=north] {Inclusion probabilities};
\draw (!>.south) |- ([xshift=10pt, yshift=10pt]c) -- ([xshift=10pt]d);
\draw (!>>>.south) |- ([xshift=20pt, yshift=20pt]c) -- ([xshift=20pt]d);
\draw (!>>>>.south) |- ([xshift=30pt, yshift=10pt]c) -- ([xshift=30pt]d);
\draw (!>>>>>.south) |- ([xshift=40pt]c) -- ([xshift=40pt]d);
\draw (ip2.south) |- ([xshift=50pt,yshift=-10pt]c) -- ([xshift=50pt]d);
}
]
]
[\Lambda
[SS
]
]
]
[Resampling
[\lambda_{MB}
[PR, name=iv2
]
]
[\lambda_{ENC}
[LR
]
]
[\Lambda
[SR
]
]
]
]
]
[Bayesian (Spike \& slab prior)
[BoomSpikeSlab
[MCMC
[{EMS=1}
[BMA, just=Model
]
]
[EMS_{CV}, just=Tuning parameter
[BMAC, name=ip2,
tikz={
\draw [decorate, decoration={brace, amplitude=5pt}, thick] (right just 4.north east) +(5pt,0) coordinate (e) -- (e |- right just 5.south) node [midway, right, xshift=5pt, justifier format, align=left] {Ensemble\\Characteristics};
}
]
]
]
]
]
]
\end{justtree}
\end{center}
\footnotesize% note that this is a switch - it does not take an argument
\textbf{ENC:} The baseline penalized regression model. Elastic net with $\lambda_{optimal} =\lambda_{ENC}$ derived from cross-validation (CV), \textbf{Ensembles based on 100 subsamples:} \textbf{PS:} Meinshausen \& B{\"u}hlmann's algorithm with a single $\lambda_{optimal} = \lambda_{MB}$ selected to minimize the expected number of false positives, \textbf{LS:} Single $\lambda_{optimal} = \lambda_{ENC}$ with no variable selection, \textbf{SS:} Stability selection across the entire 100 $\lambda \in \Lambda$ grid with no variable selection, \textbf{Ensembles based on 100 resamples: }\textbf{PR, LR, SR:} Identical to PS, PR and LR, respectively, with model space constructed through resampling. \textbf{BMA:} Bayesian model averaging with expected model size ($EMS$) = 1, \textbf{BMAC:} BMA with EMS determined by CV ($EMS_{CV}$).
\end{sidewaysfigure}
\end{document}
Best Answer
Here's an implementation using also
siunitx
. You should adjust the settings fortable-format
according to the real data.I don't think that the stripes are good, though, so I also add the “stripe free” version (removing
\rowcolors
and\rowcolor
commands).