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}

MERose
  • 228
Dennis
  • 1,613

2 Answers2

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.

David Carlisle
  • 757,742
  • 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 02 '12 at 13:58
  • It might be better to solve this in a follow-up question – Dennis Aug 02 '12 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
Troy
  • 13,741