While experimenting with different table-packages, I realised, that each package basically stands for itself and often lacks in compatibility with other great packages.
So I tried to create a table in the style of the booktabs-package (only horizontal lines), but with the functionality of the makecell-package (\thead, \makegapedcells, ...) and the possibility to color the rows (which is not very intuitive with booktabs, as discussed here.)
I made a little comparison between different table-configurations:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[skip=10pt]{parskip}
\usepackage[table]{xcolor}
\usepackage{rotating}
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage[column=Q]{cellspace} % changed to Q for simultaneous use of siunitx
\newcommand{\tableComment}[2]{
\begin{tabular}{m{4.5cm}}
#1\\[5pt]#2
\end{tabular}}
\renewcommand{\theadfont}{\itshape}
\renewcommand{\theadgape}{}
\renewcommand{\theadalign}{cc}
\setcellgapes{1pt}
\renewcommand{\cellrotangle}{90}
\newcommand{\TopRule}{\Xhline{1pt}}
\newcommand{\MidRule}{\Xhline{.5pt}}
\newcommand{\BottomRule}{\Xhline{1pt}}
\begin{document}
\tableComment{1: Standard Lines, Head with \texttt{makecell}, no additional spacing}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{2: Standard Lines, Head with \texttt{makecell}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\hline
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \hline
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \hline
\end{tabular}
}
\tableComment{3: Lines with \texttt{Xhline}, Head with \texttt{makecell}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}\\
\tableComment{4: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{5: Lines with \texttt{booktabs}, Head with \texttt{makecell}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
My Head & \makecell{My second\\ Head} \\ \midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{6: Lines with \texttt{Xhline}, Head with \texttt{thead}, spacing with \texttt{cellspace}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\thead{My Head} & \thead{My second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\settowidth\rotheadsize{\theadfont second}
\tableComment{7: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{callspace} }
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{QlQl}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\tableComment{8: Lines with \texttt{booktabs}, Head with \texttt{rothead}, spacing with \texttt{booktabs}}
{
\rowcolors{1}{gray!20}{white}
\begin{tabular}{ll}\toprule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\\midrule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \bottomrule
\end{tabular}
}
\tableComment{9: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{makegapedcells}}
{
\rowcolors{1}{gray!20}{white}
\makegapedcells
\begin{tabular}{ll}\TopRule
\rowcolor{gray!40}
\rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule
some content & $\dfrac{1}{2}$ \\
foo & bar \\ \BottomRule
\end{tabular}
}
\end{document}
As you can see, in almost every combination of packages there are some difficulties (or it simply doesn't look good). My favourites are Versions 3 and 6.
But I found no solutions for rotated cells, or by using \makegapedcells
How would you create colored tables in booktabs-style? (And what does the booktabs-package actually do except introducing new horizontal lines and changing the vertical space?). And why does \makegapedcells delete all colors except inside the \thead?



\renewcommand{\theadfont}{\itshape\cellcolor{gray!40}} \tableComment{10: Lines with \texttt{Xhline}, Head with \texttt{rothead}, spacing with \texttt{cellspace}, color with \texttt{cellcolor}} { \rowcolors{3}{gray!20}{white} \begin{tabular}{QlQl}\TopRule %\rowcolor{gray!40} \rothead{My\\Head} & \rothead{My\\second\\ Head} \\ \MidRule some content & $\dfrac{1}{2}$ \\ foo & bar \\ \BottomRule \end{tabular} }as an alternative for colored cells with rotated text? – leandriis Aug 17 '19 at 12:07