Graphics, Figures & Tables ⇒ \cellcolor error? (colortbl package)
\cellcolor error? (colortbl package)
In my report I want to use a table. Some cells of this table needs to be highlighted in different color, however the \cellcolor command does not work (while for example the \rowcolor does). Aneyone knows what I'm doing wrong?
Code:
documentclass[a4paper]{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{colortbl}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{llllll}
\toprule
& \multicolumn{ 2}{c}{{\bf Plan A}} & {\bf Plan B} & \multicolumn{ 2}{c}{{\bf Plan C}} \\
\hline
& {\bf Local} & {\bf Municipal} & {\bf Local} & {\bf Local} & {\bf Municipal} \\
\midrule
{\bf Min.} & {\bf Alternative Z4 } & Alternative X7 & \rowcolor[gray]{0.9} Alternative P1 & Alternative Q4 & \rowcolor[gray]{0.9} Alternative N3 \\
& $0.02 \pm 0.01$ & $0.04$ & \rowcolor[gray]{0.9} $0.02\pm 0.01$ & $0.004$ & \rowcolor[gray]{0.9} $0.0048$ \\
& $46 \pm 2.3 \%$ & $135 \%$ & \rowcolor[gray]{0.9} & $20 \%$ & \rowcolor[gray]{0.9} $41 \%$ \\
{\bf Max.} & Alternative V2 & Alternative V2 & Alternative K8 & \cellcolor[cmyk]{0.2,0,0,0} {\it Alternative G5 } & \cellcolor[cmyk]{0.2,0,0,0} {\it Alternative B3} \\
& $9.0 \pm 2.9$ & $1.41 \pm 0.05$ & $1.099$ & \cellcolor[cmyk]{0.2,0,0,0} $3.43 \pm 0.2$ & \cellcolor[cmyk]{0.2,0,0,0} $=3.83\pm 0.2$ \\
& $33.4\pm 6.5 \%$ & $=82.5\pm 9\%$ & $=0.080$ & \cellcolor[cmyk]{0.2,0,0,0} & \cellcolor[cmyk]{0.2,0,0,0} \\
\bottomrule
\end{tabular}
\end{table}
\end{document
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
\cellcolor error? (colortbl package)
the \rowcolor command must be used at the start of a row, and in your code you are using it twice in the wrong position (not at the start of the row).
The following code works OK:
Code: Select all
\documentclass[a4paper]{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{colortbl}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tabular}{llllll}
\toprule
& \multicolumn{ 2}{c}{{\bfseries Plan A}} & {\bfseries Plan B} & \multicolumn{ 2}{c}
{{\bfseries Plan C}} \\
\hline
& {\bfseries Local} & {\bfseries Municipal} & {\bfseries Local} & {\bfseries Local} &
{\bfseries Municipal} \\
\midrule
{\bfseries Min.} & {\bfseries Alternative Z4 } & Alternative X7 & \cellcolor[gray]{0.9}
Alternative P1 & Alternative Q4 & \cellcolor[gray]{0.9} Alternative N3 \\
& $0.02 \pm 0.01$ & $0.04$ & \cellcolor[gray]{0.9} $0.02\pm 0.01$ & $0.004$ &
\cellcolor[gray]{0.9} $0.0048$ \\
& $46 \pm 2.3 \%$ & $135 \%$ & \cellcolor[gray]{0.9} & $20 \%$ &
\cellcolor[gray]{0.9} $41 \%$ \\
{\bfseries Max.} & Alternative V2 & Alternative V2 & Alternative K8 &
\cellcolor[cmyk]{0.2,0,0,0} {\it Alternative G5 } &
\cellcolor[cmyk]{0.2,0,0,0} {\it Alternative B3} \\
& $9.0 \pm 2.9$ & $1.41 \pm 0.05$ & $1.099$ & \cellcolor[cmyk]{0.2,0,0,0} $3.43 \pm
0.2$ & \cellcolor[cmyk]{0.2,0,0,0} $=3.83\pm 0.2$ \\
& $33.4\pm 6.5 \%$ & $=82.5\pm 9\%$ & $=0.080$ & \cellcolor[cmyk]{0.2,0,0,0} &
\cellcolor[cmyk]{0.2,0,0,0} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
\cellcolor error? (colortbl package)
First of all, thanks for your help. Unfortunately, the \rowcolor command is not the problem, that works fine. The \cellcolor command is the one which is not working.
If I run for example the code in your answer, I get the error: Undefined control sequence. 1.13 ...rnative Z4 } & Alternative X7 & \cellcolor [gray]{0.9} ?
Cheers, Bill
p.s. sorry for the \bf, I'll change it...
\cellcolor error? (colortbl package)
If you are getting errors with the exact code example that I posted, then I suspect that you might have old versions of some package(s). Let's consider that possibility first: add the command \listfiles before the \documentclass{article} line in my example code and compile your document. Now open the auxiliar .log file (it can be found in the same directory that contains the .tex file) and search for the section *File List* (this list was created by the \listfiles command).
Below, you can see the *File List* that I obtained after compilation of my example; compare it with yours to see if some packages are out of date. If so, please update your LaTeX system; if that's not the problem, then please attach to your next post the complete .log file.
Code: Select all
*File List*
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
booktabs.sty 2005/04/14 v1.61803 publication quality tables
multirow.sty
colortbl.sty 2001/02/13 v0.1j Color table columns (DPC)
array.sty 2008/09/09 v2.4c Tabular extension package (FMi)
color.sty 2005/11/14 v1.0j Standard LaTeX Color (DPC)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pdftex.def 2009/08/25 v0.04m Graphics/color for pdfTeX
supp-pdf.mkii
***********
Re: \cellcolor error? (colortbl package)
cheers, Bill