I want to fill booktabs
table cells in a custom manner. I did two examples as below, one with kerning and the other is straight booktabs
table. The first problem is in both tables, coloring that is not at the table border overflows up to the border of the next column (the red line in the image indicates this). The second problem is kerning macros (or whatever they are called), distracts the positioning of cell texts, as seen in the image. The texts are biased to bottom of the cell.
- How can I prevent overflowing in single cell coloring?
- How can I remove position bias? (Maybe this can be inherently fixed after finding a solution to the first question)
\begin{table}[b!]
\centering
\caption{Kern'ed Table.}
\label{tab:graphExplanation}
%\renewcommand{\arraystretch}{1.15}
\extrarowheight=\aboverulesep
\addtolength{\extrarowheight}{\belowrulesep}
\aboverulesep=0pt
\belowrulesep=0pt
\begin{tabular}{>{\kern-\tabcolsep}cccc<{\kern-\tabcolsep}}
\toprule
\multicolumn{2}{c}{MulC1}
& \multicolumn{2}{c}{MulC2} \\
\cmidrule(r){1-2}
\cmidrule(r){3-4}
\textbf{Col1} & \textbf{Col2} & \textbf{Col1} & \textbf{Col2} \\
Cell & \cellcolor[HTML]{C0C0C0} Cell & Cell & \cellcolor[HTML]{C0C0C0}Cell \\
Cell & \cellcolor[HTML]{C0C0C0}Cell & Cell & \cellcolor[HTML]{C0C0C0}Cell \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[b!]
\centering
\caption{UnKern'ed Table.}
\label{tab:graphExplanation}
%\renewcommand{\arraystretch}{1.15}
\begin{tabular}{@{}cccc@{}}
\toprule
\multicolumn{2}{c}{MulC1}
& \multicolumn{2}{c}{MulC2} \\
\cmidrule(r){1-2}
\cmidrule(r){3-4}
\textbf{Col1} & \textbf{Col2} & \textbf{Col1} & \textbf{Col2} \\
Cell & \cellcolor[HTML]{C0C0C0} Cell & Cell & \cellcolor[HTML]{C0C0C0}Cell \\
Cell & \cellcolor[HTML]{C0C0C0}Cell & Cell & \cellcolor[HTML]{C0C0C0}Cell \\
\bottomrule
\end{tabular}
\end{table}
booktabs
, thus there is a solid instead of a split line below the headers.cellspace
package instead: it ensures a minimal vertical spacing at the top and bottom of cells in a column.nicematrix
package below in the answer