I use a colored Table to illustrate a concept called 5-fold cross-validation. (Code is below). In latex, it looks as follows:
When I convert this to html using tex4ebook cv_table.tex
I get this:
Note that the last blue/yellow column is a little wider (undesired), because what used to be space after the column is absorbed into the column (see \newcolumntype{L}
in the code).
To avoid the interrupted black lines in all tables, I am using the following my.cfg
from here:
\Preamble{xhtml}
\Css{table.tabular{border-collapse: collapse; border-spacing: 0;}}
\begin{document}
\EndPreamble
Using tex4ebook -c my.cfg cv_table.tex
I get this:
This solves the interrupted black-line problem for all tables, but also removes the white space between the colored elements.
I tried stretching the width of the cells using \hspace{}
, but didn’t succeed .
My questions are:
- Is there a way to add space between the colored elements?
- Can I stretch the width of the cells somehow?
MWE
\documentclass{article}
\usepackage{booktabs}
\usepackage[usenames, dvipsnames,table]{xcolor}
\usepackage{array} % needed for \newcolumntype
\newcolumntype{K}{!{\color{white}\ }p{1cm}}
\newcolumntype{L}{!{\color{white}\ \ \ }p{1.5cm}} % has extra white space
\begin{document}
\begin{figure}[t]
\begin{center}
\begin{tabular}{cKKKKKL}\toprule
Fold & & & & & & Test Data \\ \midrule
1 \cellcolor{white} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{yellow} & \cellcolor{white} \\\addlinespace[.25em]
2 \cellcolor{white} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{yellow} & \cellcolor{cyan} & \cellcolor{white} \\\addlinespace[.25em]
3 \cellcolor{white} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{yellow} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{magenta} \\\addlinespace[.25em]
4 \cellcolor{white} & \cellcolor{cyan} & \cellcolor{yellow} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{white} \\\addlinespace[.25em]
5 \cellcolor{white} & \cellcolor{yellow} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{cyan} & \cellcolor{white} \\\bottomrule
\end{tabular}
\end{center}
\end{figure}
\end{document}