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.

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}
\linespread{1.3}
\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}
share|improve this question
add comment

1 Answer

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}

Longtable with \hhline horizontal lines

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:

\hhline artefact in longtable

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:

Longtable with vertical misaligned lines

These are more readily fixed using

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

instead of

\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
share|improve this answer
    
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
2  
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
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.