2

I use a colored Table to illustrate a concept called 5-fold cross-validation. (Code is below). In latex, it looks as follows: enter image description here

When I convert this to html using tex4ebook cv_table.tex I get this:

enter image description here

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:

enter image description here

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:

  1. Is there a way to add space between the colored elements?
  2. 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}

1 Answer 1

3

Try this configuration file:

\Preamble{xhtml}
% redefine column type to remove extra white space
\newcolumntype{L}{!{\color{white}\ }p{1.5cm}} 
\catcode`\:=11
% separatiobn between table cells
\Css{table.tabular td{border: 1px solid white;} }

% minimal cell width
\Css{table.tabular td{min-width:2em;}}

% we must redefine booktabs rule styling.
\Configure{toprule}
   {\Css{tr\#TBL-\TableNo-\ifnum \HRow=0
          1- td {border-top:2px solid \#\hline:color;}
     \else
          \HRow- td{border-bottom: 2px solid \#\hline:color;}
     \fi
   }}
\Configure{bottomrule}
   {\Css{tr\#TBL-\TableNo-\HRow- td {border-bottom:2px solid  \#\hline:color}}}
\Configure{midrule}
   {\Css{tr\#TBL-\TableNo-\HRow- td {border-bottom: 1.5px solid \#\hline:color}}}
\catcode`\:=12
\begin{document}
\EndPreamble

This is the result:

enter image description here

There are some catches: border size for rules must be larger than border size of other cells. Otherwise, you will get gaps in rules.

2
  • My humble opinion on tour code. The White horizontal and verticals Lines are not tickness.+1
    – Sebastiano
    Commented Nov 24, 2021 at 10:23
  • 2
    @Sebastiano the problem is, that it is quite hard to style table borders using CSS, and some usual methods, like margins or paddings don't work. So I have to use this work-around.
    – michal.h21
    Commented Nov 24, 2021 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .