Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to write \clines (or \hhline) in colored tables so that the color of the cell does not hide the line?

Here are two solutions but neither of them works fine.

\documentclass[a4paper,11pt]{article} 
\usepackage{colortbl} 
\usepackage{hhline} 
\usepackage{multirow} 

\begin{document} 

First try with \verb+\cline+

\begin{figure}[hbt]
\centering
\small\sf
\begin{tabular}{|c|c|>{\columncolor[gray]{.8}}c|c|c|c|} \hline
\rowcolor[gray]{.8} &  &  & \multicolumn{3}{c|}{Year} \\ \hline
\rowcolor[gray]{.8} Country & GOR & UA &  2006 &  2007 &  2008 \\ \hline
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} &  Milton Keynes & 92 & 94 & 96 \\\cline{3-6}
\cellcolor[gray]{.8} & \multirow{-2}{*}{\cellcolor[gray]{.8}South East} & Reading & 58 & 58 & 60 \\\cline{2-6}
\multirow{-3}{*}{\cellcolor[gray]{.8}England} & \cellcolor[gray]{.8} South West &  Bournemouth& 71 & 72 & 73 \\ \hline
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} & Cardiff & 132.1 & 134.2 & 136.7 \\\cline{3-6} 
\multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & \multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & Newport & 58.7 & $\perp$ & 59.6 \\ \hline
\end{tabular}  
\caption{The clines are somehow hidden by the cell color}
\end{figure}    

Second try with \verb+\hhline+

\begin{figure}[hbt]
\centering
\small\sf
\begin{tabular}{|c|c|>{\columncolor[gray]{.8}}c|c|c|c|} \hline
\rowcolor[gray]{.8} &  &  & \multicolumn{3}{c|}{Year} \\ \hline
\rowcolor[gray]{.8} Country & GOR & UA &  2006 &  2007 &  2008 \\ \hline
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} &  Milton Keynes & 92 & 94 & 96 \\\hhline{~~----}
\cellcolor[gray]{.8} & \multirow{-2}{*}{\cellcolor[gray]{.8}South East} & Reading & 58 & 58 & 60 \\\hhline{~-----}
\multirow{-3}{*}{\cellcolor[gray]{.8}England} & \cellcolor[gray]{.8} South West &  Bournemouth& 71 & 72 & 73 \\ \hline
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} & Cardiff & 132.1 & 134.2 & 136.7 \\ \hhline{~~----} 
\multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & \multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & Newport & 58.7 & $\perp$ & 59.6 \\ \hline
\end{tabular}  
\caption{Now there is a white line where it shouldn't be}
\end{figure}    

\end{document} 
share|improve this question
add comment

2 Answers 2

enter image description here

You shouldn't need the \noalign{\vskip and the amounts in the fudge factor probably depend on which pdf viewer you use, but sometimes it helps to keep the rules a little bit away from the coloured panels.

\documentclass[a4paper,11pt]{article} 
\usepackage{colortbl} 
\usepackage{hhline} 
\usepackage{multirow} 

\begin{document} 


\begin{figure}[hbt]
\centering
\small\sf
\begin{tabular}{|c|c|>{\columncolor[gray]{.8}}c|c|c|c|} \hhline{|*6{-}|}\noalign{\vskip.2pt}
\rowcolor[gray]{.8} &  &  & \multicolumn{3}{c|}{Year} \\ \hhline{|*6{-}|}\noalign{\vskip.2pt}
\rowcolor[gray]{.8} Country & GOR & UA &  2006 &  2007 &  2008 \\ \hhline{|*6{-}|}\noalign{\vskip.2pt}
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} &  Milton Keynes & 92 & 94 & 96 \\\hhline{|*2{>{\arrayrulecolor[gray]{.8}}-}>{\arrayrulecolor{black}}|*4{-}|}
\cellcolor[gray]{.8} & \multirow{-2}{*}{\cellcolor[gray]{.8}South East} & Reading & 58 & 58 & 60 \\\hhline{|*1{>{\arrayrulecolor[gray]{.8}}-}*5{>{\arrayrulecolor{black}}-}|}
\multirow{-3}{*}{\cellcolor[gray]{.8}England} & \cellcolor[gray]{.8} South West &  Bournemouth& 71 & 72 & 73 \\ \hline
\cellcolor[gray]{.8} & \cellcolor[gray]{.8} & Cardiff & 132.1 & 134.2 & 136.7 \\ \hhline{|*2{>{\arrayrulecolor[gray]{.8}}-}*4{>{\arrayrulecolor{black}}-}|}
\multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & \multirow{-2}{*}{\cellcolor[gray]{.8}Wales} & Newport & 58.7 & $\perp$ & 59.6 \\ \hhline{|*6{-}|}
\end{tabular}  
\caption{Now there is a white line where it shouldn't be}
\end{figure}    

\end{document} 
share|improve this answer
add comment

This code seems to work, for both vertical and horizontal lines:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{colortbl}

\begin{document}

\begin{table}[h]
\begin{tabular}{|l|c|c|c|c|}
\hline
\multicolumn{5}{|c|}{Type} \\
\hline
  & A  &    B & C & D \\
    \hline
    X & 53,2\%  &  \cellcolor[gray]{.9}51,6\%  &  \cellcolor[gray]{.9}49\% & 49\% \\
    \hhline{~~|~|~~|}
    Y  & 53,8\%  &  52,2\%  & 49\% & 49\% \\
\hline
\end{tabular}
\end{table}

\begin{table}[h]
\begin{tabular}{|l|c|c|c|c|}
\hline
\multicolumn{5}{|c|}{Type} \\
\hline
  & A  &    B & C & D \\
    \hline
    X & 53,2\%  &  \cellcolor[gray]{.9}51,6\%  &  \cellcolor[gray]{.9}49\% & 49\% \\
    \hhline{~~|-|-~|}
    Y  & 53,8\%  &  52,2\%  & 49\% & 49\% \\
\hline
\end{tabular}
\end{table}
\end{document} 

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.