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.

In the following application of \rowcolors from the colortbl package, how can I specify the option to start the alternating color pattern from the 3rd row onwards? The first two rows in this case are part of the table heading, so I don't want the alternating background color to begin until the 3rd row down.

If you can, please refer to any relevant sections in the package manual - if it's there I couldn't seem to find it.

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage[x11names,dvipsnames,table]{xcolor} %for use in color links
\usepackage{colortbl}

\begin{document}
\rowcolors{1}{white}{Wheat1}
\begin{tabular}{l l l l l l}
\toprule
        &   \multicolumn{4}{l}{Training data set}   &   Test data set\\
\cmidrule(l r){2-5} \cmidrule(l){6-6}
Method  &   MSE &   Var(Z)  &   $R^2$   &   RMSE    &   RMSE\\
\cmidrule(r){1 - 1} \cmidrule(l r){2-2} \cmidrule(l r){3-3} \cmidrule(l r){4-4} \cmidrule(l r){5-5} \cmidrule(l){6-6}
Global polynomial, order 1 & 1 & 2 & 3 & 4 & 5 \\
Global polynomial, order 3 & 6 & 7 & 8 & 9 & 10 \\
Global polynomial, order 5 & 11 & 12 & 13 & 14 & 15 \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

share|improve this question
2  
@xport: I notice that the edit here includes UK<->US spellings. I think in general it's best to leave these to the OP. (Other edits perfectly sensible, of course.) –  Joseph Wright May 30 '11 at 13:16
    
@Joseph: the first edit, I added 4 ``` to the body but I still needed 2 more characters to be edited. Therefore I am forced to remove 2 u from 2 colour. Several seconds later, I did the second edit, removing the word "thanks". –  xport May 30 '11 at 13:26
    
@xport: Fine, it's not a big issue. Just thought I'd mention it as I saw it. –  Joseph Wright May 30 '11 at 13:27
add comment

1 Answer

up vote 2 down vote accepted

The first mandatory argument of the \rowcolor command indicates the number of the first row which should be colored according to the color scheme given by the second and third mandatory arguments.

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage[table,x11names,dvipsnames,table]{xcolor}

\begin{document}

\rowcolors{5}{}{Wheat1}
\begin{tabular}{l l l l l l}
  \toprule
  &   \multicolumn{4}{l}{Training data set}   &   Test data set \\
  \cmidrule(l r){2-5} \cmidrule(l){6-6} 
  Method  &   MSE &   Var(Z)  &   $R^2$   &   RMSE    &   RMSE\\
  \cmidrule(r){1 - 1} \cmidrule(l r){2-2} \cmidrule(l r){3-3} \cmidrule(l r){4-4} \cmidrule(l r){5-5}   \cmidrule(l){6-6}
  Global polynomial, order 1 & 1 & 2 & 3 & 4 & 5 \\
  Global polynomial, order 3 & 6 & 7 & 8 & 9 & 10 \\
  Global polynomial, order 5 & 11 & 12 & 13 & 14 & 15 \\
  \bottomrule
\end{tabular}

\end{document}

EDIT2: or use \rowcolors{3}{Wheat1}{} in the above code if you want the first data row to have the Wheat1 color; in my code, the pattern will start having the first data row with white color.

The table option for xcolor loads the colortbl package, so there's no need to load it separately.

EDIT: information on the \rowcolor command can be found in the colortbl documentation and in Section 2.12 Color in tables in the xcolor documentation.

share|improve this answer
    
Thanks, Gonz. It worked. :) I'm just still a little unsure about the \rowcolors arguments and the contents of these arguments, as it isn't really explained explicitly in the manuals. The first argument is not simply the row number to start the row shading on is it? If not, then how is it defined? Secondly, I guessed you removed the "white" because it was redundant? –  ptrcao May 30 '11 at 18:31
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.