11

I'm having an issue where \cline appears to be drawn under the fill for table colours.

With \hline

enter image description here

With \cline

(to remove the line above the cell I want blank)

enter image description here

The line is still there, only very very thin. This doesn't always display or print. Is there anything simple I can do to fix this?

Here's the source for my example:

\documentclass{article}

\usepackage[table]{xcolor}

%odd/eaven colours for tables \rowcolors{2}{gray!10}{white}

%to change cells of the title row \newcommand{\titlecol}{\cellcolor{gray!30}}

\begin{document}

\begin{table}[!ht] \centering \begin{tabular}{|l| c c | c c |} \cline{2-5} %\hline \rowcolor{white} %first cell is excluded from the table \multicolumn{1}{c|}{} & \multicolumn{2}{c|}{\titlecol Title1} & \multicolumn{2}{c|}{\titlecol Title2} \ \hline A & 0 & 1 & 2 & 3 \ B & 0 & 1 & 2 & 3 \ C & 0 & 1 & 2 & 3 \ D & 0 & 1 & 2 & 3 \ \hline \end{tabular} \caption{Caption.} \label{mytable} \end{table}

\end{document}

jozxyqk
  • 1,089

3 Answers3

5

Thanks all for your answers and comments!

There's also this, now I know what to search for: Colored tables and cline/hhline

This is what I ended up with (using \hhline{~|--|--|}):

enter image description here

I've only looked briefly, but it looks like this is what the characters in hline do:

  • ~ no line for one cell
  • | the corner between horizontal and vertical lines, although I'm not sure if I needed the middle one
  • - the line for a cell

See the docs

\documentclass{article}

\usepackage[table]{xcolor} \usepackage{hhline}

%odd/eaven colours for tables \rowcolors{2}{gray!10}{white}

\newcommand{\titlecol}{\cellcolor{gray!30}}

\begin{document}

\begin{table}[!ht] \centering \begin{tabular}{|l| c c | c c |} \hhline{~|*4{-}|} %\cline{2-5} %\hline \rowcolor{white} \multicolumn{1}{c|}{} & \multicolumn{2}{c|}{\titlecol Title1} & \multicolumn{2}{c|}{\titlecol Title2} \ \hline A & 0 & 1 & 2 & 3 \ B & 0 & 1 & 2 & 3 \ C & 0 & 1 & 2 & 3 \ D & 0 & 1 & 2 & 3 \ \hline \end{tabular} \caption{Caption.} \label{mytable} \end{table}

\end{document}

jozxyqk
  • 1,089
2

I found out the following: the line is not too thin, it is simply overwritten by the filled cells. Some pdf readers notice the small difference in y-value and paint the line, others don't.

A similar question has been asked here:

\cline doesn't work

I propose you solve this problem with one of the proposed methods as listed in the extended answer on this question.

0

For information, here is (easy) way to construct that table with {NiceTabular} of nicematrix.

In that environment, there is a key corners to compute the empty corners of the tabular (here the corner in the north-west`). Then the rules, are not drawn in the corners and the instructions of color don't color the cells in the corners.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{table}[!ht] \centering \begin{NiceTabular}{|l|cc|cc|}[color-inside,corners=NW] % NW : north-west \Hline \rowcolor{gray!30} & \Block{1-2}{Title1} && \Block{1-2}{Title2} \ \Hline \rowcolors{gray!10}{} A & 0 & 1 & 2 & 3 \ B & 0 & 1 & 2 & 3 \ C & 0 & 1 & 2 & 3 \ D & 0 & 1 & 2 & 3 \ \Hline \end{NiceTabular} \caption{Caption.} \label{mytable} \end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250