# Cell shading without removing lines

I was wondering if there is any way to shade some cells in table without removing lines. I starged with this command

\cellcolor[gray]{0.9}


however upper line of the cell disapeard. Is there any better way to color some cells ?? PS I use longtable

Here is the code

    \documentclass[a4paper,12pt]{mwrep}
\usepackage[MeX]{polski}
\usepackage[cp1250]{inputenc}
\usepackage[left=3.0cm,right=3cm,top=3.0cm,bottom=3.0cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{algorithmic}
\usepackage{colortbl}
\usepackage{dcolumn}
\usepackage{float}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage[centerlast]{caption}
\usepackage{multirow}
\usepackage[section] {placeins}
\usepackage{booktabs}
\usepackage{xcolor}
\begin{document}
\begin{longtable}{!{\vrule width 2pt}c!{\vrule width 2pt}c!{\vrule width 2pt}c|c|c!{\vrule width 2pt}c|c|c!{\vrule width 2pt}c!{\vrule width 2pt}c!{\vrule width 2pt}}
\caption{Zależność wydajności algorytmu od jego parametrów.}
\label{tab:parameters}
\\ \hline
\multirow{2}{*}{Parametr} & \multirow{2}{*}{Wartość} & \multicolumn{3}{|c!{\vrule width 2pt}}{\textbf{Czas[s]}}  & \multicolumn{3}{|c!{\vrule width 2pt}}{$\rho_{a}$} \\ \cline{3-10}
& & Zestaw 1 & Zestaw 2  & Zestaw 3  & Zestaw 1  & Zestaw 2  & Zestaw 3 \\ \hline
\multirow{4}{*}{$\rho_{select}$} &  0.5 &   58.0    &   266.4   &   131.4   &   0.98    &   0.8 &   0.95        \\ \cline{2-10}
& 0.6   &   55.0    &   270.1   &   145.6   &   0.95    &   0.85    &   0.85        \\ \cline{2-10}
& \cellcolor[gray]{0.9} 0.7 &   55.3    &   256.6   &   143.1   &   0.99    &   0.75    &   0.90        \\ \cline{2-10}
& 0.8   &   72.0    &   347.2   &   156.9   &   1.00    &   0.87    &   0.97        \\ \hline
\end{longtable}
\end{document}


Your problem here is noted as a 'feature' of \cline{...} when using it in conjunction with \cellcolor{...}. The colortbl package documentation mentions the following:

10 Less fun with \cline

Lines produced by \cline are coloured if you use \arrayrulecolor but you may not notice as they are covered up by any colour pannels in the following row. This is a 'feature' of \cline. If using this package you would probably better using the - rule type in a \hhline argument, rather than \cline.

Therefore, my suggestion uses the hhline package from the same author (David Carlisle). See the package documentation for more details on how to specify the \hhline rules:

\documentclass[a4paper,12pt]{mwrep}
...
\usepackage{hhline}% http://ctan.org/pkg/hhline
\begin{longtable}{!{\vrule width 2pt}c!{\vrule width 2pt}c!{\vrule width 2pt}c|c|c!{\vrule width 2pt}c|c|c!{\vrule width 2pt}c!{\vrule width 2pt}c!{\vrule width 2pt}}
\caption{Zaleznosc wydajnosci algorytmu od jego parametrów.}
\label{tab:parameters}
\\ \hline
\multirow{2}{*}{Parametr} & \multirow{2}{*}{Wartosc} & \multicolumn{3}{|c!{\vrule width 2pt}}{\textbf{Czas[s]}}  & \multicolumn{3}{|c!{\vrule width 2pt}}{$\rho_{a}$} \\ \cline{3-10}
& & Zestaw 1 & Zestaw 2  & Zestaw 3  & Zestaw 1  & Zestaw 2  & Zestaw 3 \\ \hline
\multirow{4}{*}{$\rho_{select}$} &  0.5 &   58.0    &   266.4   &   131.4   &   0.98    &   0.8 &   0.95        \\ \cline{2-10}
& 0.6   &   55.0    &   270.1   &   145.6   &   0.95    &   0.85    &   0.85        \\ \hhline{|~|-|-|-|-|-|-|-|}% New line specification
& \cellcolor[gray]{0.9} 0.7 &   55.3    &   256.6   &   143.1   &   0.99    &   0.75    &   0.90        \\ \cline{2-10}
& 0.8   &   72.0    &   347.2   &   156.9   &   1.00    &   0.87    &   0.97        \\ \hline
\end{longtable}
\end{document}


However, the problem is not entire gone as you can see when you zoom in to the spread of the empty horizontal line (via the ~ \hhline specifier) across column 1:

I think this stems from your use of \vrule width 2pt as your column rules/widths. And, as such, may be hard to circumvent. This minute problem will most certainly not show up in print, and may therefore be not a problem. Moreover, similar misalignment have gone unnoticed across some of the vertical lines in your columns:

These are more readily fixed using

\multicolumn{3}{c!{\vrule width 2pt}}{\textbf{Czas[s]}} &
\multicolumn{3}{c!{\vrule width 2pt}}{$\rho_{a}$} \


\multicolumn{3}{|c!{\vrule width 2pt}}{\textbf{Czas[s]}} &
\multicolumn{3}{|c!{\vrule width 2pt}}{$\rho_{a}$} \


Also note the slight misaligned 0.7 with the rest of the columns entries. That's from leaving a space between the cell colour definition and the actual cell entry:

\cellcolor[gray]{0.9} 0.7


Fix this with:

\cellcolor[gray]{0.9}0.7

• Hmm, I checked my document in quite a lot of zoom levels, but all the time the upper lines are missing – geronimo Aug 6 '11 at 23:18
• Then post a minimal working example of the longtable for others to work with. – Werner Aug 6 '11 at 23:36
• I edited my question and added some code – geronimo Aug 7 '11 at 10:51
• See my revised answer that (somewhat) addresses your concern. Perhaps not optimal, but I'm not sure whether this is sufficient. Your problem deals with a 'feature' of the \cline command. – Werner Aug 7 '11 at 16:42

The latest version of nicematrix (v 4.3 2020-06-12) provides a solution to that problem. In the environment {NiceTabular} of nicematrix, you have a key code-before with instructions (such as \cellcolor) to color cells, columns and rows before the rules are drawn.

\documentclass[a4paper,10pt,landscape]{article}
\usepackage{graphicx}
\usepackage{nicematrix}
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}

\renewcommand{\arraystretch}{1.2}
\newcolumntype{I}{!{\vrule width 2pt}}
\begin{NiceTabular}{IwC{17mm}IwC{13mm}IC|C|CIC|C|CI}%
[code-before = \cellcolor{gray!15}{5-2},standard-cline]
\hline
\Block{2-1}{Parametr} & \Block{2-1}{Wartość} & \multicolumn{3}{C!{\vrule width 2pt}}{\textbf{Czas[s]}} &
\multicolumn{3}{C!{\vrule width 2pt}}{$\rho_{a}$} \\
\cline{3-8}
& & Zestaw 1 & Zestaw 2  & Zestaw 3  & Zestaw 1  & Zestaw 2  & Zestaw 3 \\
\hline
\Block{4-1}{$\rho_{\text{select}}$} &  0.5 &   58.0    &   266.4   &   131.4   &   0.98    &   0.8 &   0.95 \\
\cline{2-8}
& 0.6 &   55.0    &   270.1   &   145.6   &   0.95    &   0.85    &   0.85 \\
\cline{2-8}
& 0.7 &   55.3    &   256.6   &   143.1   &   0.99    &   0.75    &   0.90 \\
\cline{2-8}
& 0.8 &   72.0    &   347.2   &   156.9   &   1.00    &   0.87    &   0.97 \\
\hline
\end{NiceTabular}
\end{document}


I have used the key standard-cline in order to have \cline commands with the standard behaviour, that is to say protruding in the following row (as explained by Werner in its answer).

I have also used the command \Block prodvided by nicematrix but the same result could have acheived by using multirow here.

Last remark: the rules around the colored cell will not vanish in the PDF viewers, wheatever zoom level is used.

• In this answer, since version 5.0 of nicematrix one must write c instead of C in the preamble of {NiceTabular} (but there is an option for backward compatibility). – F. Pantigny Jul 18 at 21:01