24

I have a table which I want to fill with multiple colors, each cell possibly different from another. Which means, I can't make use of e.g. \columncolor (as in this post).

While the table without any colors looks just fine (code at the end): empty table

...the table with one or more filled cells overwrites the table grid. filled tables

So my question is: Is there a way to, for example, redraw the grid after filling the cells or something?

Here is my code:

\documentclass[11pt]{article}

\usepackage{color}
\usepackage{colortbl}
\usepackage{multirow}

\newlength{\Oldarrayrulewidth}
% Cline redefining to add line thickness
\newcommand{\Cline}[2]{%
  \noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
  \noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
  \noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}
}


\definecolor{intnull}{RGB}{213,229,255}
\definecolor{inteins}{RGB}{128,179,255}
\definecolor{intzwei}{RGB}{42,127,255}
\definecolor{intdrei}{RGB}{0,85,212}
\definecolor{intvier}{RGB}{0,51,128}
\definecolor{intfunf}{RGB}{0,34,85}


\begin{document}
% Empty table
\begin{tabular}{*{5}{!{\vrule width 1.5pt}p{1.5cm}}!{\vrule width 1.5pt}l}
\centering 4 &
\centering 10 &
\centering 24 &
\centering 48 &
\centering 72 &\\ \Cline{1.5pt}{0-4}
 &  &  &  &  & Optic tectum \\ \Cline{1.5pt}{3-5}
 &  &  &  &  & Retina \\ \Cline{1.5pt}{3-5}
 &  &  &  &  & Myomeres \\ \Cline{1.5pt}{0-4}
 &  &  &  &  & Arches \\ \Cline{1.5pt}{0-4}
\end{tabular} \\

\hspace*{1cm}

% Partically filled table
\begin{tabular}{*{5}{!{\vrule width 1.5pt}p{1.5cm}}!{\vrule width 1.5pt}l}
\centering 4 &
\centering 10 &
\centering 24 &
\centering 48 &
\centering 72 &\\ \Cline{1.5pt}{0-4}
 & \cellcolor{intnull} &  & \cellcolor{intvier} &  & Optic tectum \\ \Cline{1.5pt}{3-5}
 & \cellcolor{intnull} &  & \cellcolor{intnull} &  & Retina \\ \Cline{1.5pt}{3-5}
 & \cellcolor{intnull} &  & \cellcolor{intdrei} &  & Myomeres \\ \Cline{1.5pt}{0-4}
 & \cellcolor{inteins} &  & \cellcolor{inteins} &  & Arches \\ \Cline{1.5pt}{0-4}
\end{tabular}

\end{document}
0

2 Answers 2

18

Please don't just post fragments of code that can not be run, always post complete small documents.

The fix should be exactly as in the other question. As documented colortbl is incompatible with \cline, you need to use \hhline instead. The fact that the cell backgrounds are different colours is irrelevant to the problem of \cline including negative spacing so that it comes under the colour.

2
  • 4
    This leads to new, but different problems: I read your documentation of the hhline package and used \hhline{*{2}{|~}*{3}{|-}|~|} instead of \Cline. Now I have white lines where no line should be. Using actual multirows has no different effect.
    – Dennis
    Aug 2, 2012 at 13:58
  • It might be better to solve this in a follow-up question
    – Dennis
    Aug 2, 2012 at 14:22
4

Just put the command \cellcolor[]{} inside brackets {} and it will not overwrite the table lines like this

\hline

{\cellcolor[gray]{.8}} Chapter & Title \\

\hline
3
  • Welcome to TeX.sx! If you indent lines by 4 spaces, they will be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). May 3, 2013 at 13:16
  • 1
    If you just use \hline and not \cline that is working perfect and is much easier implemented! I can not tick it as right answer as this is already done with the first answer. Oct 24, 2013 at 8:02
  • 1
    no, it doesn't help. I just tested it and the result is the same, I have still problems with those lines Sep 4, 2019 at 9:36

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