title: xtable - background colour of added rows
body: <p>I'm trying to make a table with inserted summary rows using xtable and knitr. I'd like to have these inserted lines in a different colour. Using the add.to.row option, I've managed to either insert the lines <em>or</em> change the colour, but not both at the same time. </p>
  
  <p>The reason I'm inserting the rows within xtable, rather than ahead of time, is that I want the "total" row to be spread over two columns due to its length in my original dataset. So the required solution would have both multicolumn cells in the summary row and a different-colour background.
  I'm at the very beginning of my Latex learning curve, and any help would be greatly appreciated.</p>
  
  <p>Here is an example, including a fake dataset:</p>
  
  <pre><code>\usepackage{booktabs}
  \usepackage{colortbl, xcolor}
  
  \begin{document}
  
  &lt;&lt;try, echo = FALSE, eval = TRUE, results = 'asis'&gt;&gt;=  
  library(xtable)
  dat &lt;- data.frame(type = c(rep("a", 5), rep("b", 5)), a = c(1:5, 1:5), b = 1:10, c = 21:30)
  temp &lt;- ddply(dat, .(type), summarize, SumB = sum(b))
  
  rws &lt;- which(dat$a == 5)
  col &lt;- rep("\\rowcolor[gray]{0.95}", length(rws)) ## colour definition prepared, but not used
  
  #Making the command for inserting summary rows
  temp$insert &lt;- ""
  for(i in 1:nrow(temp)){
      temp[i,]$insert &lt;- sprintf("\\multicolumn{3}{l}{Total %s} &amp;
          \\multicolumn{1}{c}{%d} \\\\ ", temp[i,]$type, temp[i,]$SumB)
              }
  
  print(xtable(dat, align = "llccc"), 
      include.rownames=FALSE,
      booktabs = TRUE, 
      sanitize.text.function=function(x){x},
      add.to.row = list(pos = as.list(rws),
          command = paste(temp$insert, sep = ",")))
  
  @
  \end{document}
  </code></pre>