亲爱的 R xtable 和 knitr 用户:我已经为这个问题苦苦挣扎了好几天,我很惊讶没有人报告过类似的案例。非常感谢您的洞察力和帮助。
我用 xtable 制作了两个或更多的表。表格中的行交替着色。第一张桌子很好。但是从第二张表(或更多)开始,最左边的标题单元格总是被涂黑。
不幸的是,这是非常可重复的。在第一张漂亮的桌子之后,我总是得到完全相同的黑色标题。这是重现它的代码:
\documentclass{article}
\usepackage{booktabs}
\usepackage{colortbl, xcolor}
\begin{document}
<<echo=TRUE,results='asis'>>=
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
mydata <- data.frame(employee, salary)
rws <- seq(1, (nrow(mydata)), by = 2)
col <- rep("\\rowcolor[gray]{0.90}", length(rws))
library(xtable)
print(xtable(mydata, caption="Test"), booktabs = TRUE,
include.rownames = FALSE, caption.placement = "top",
sanitize.colnames.function = identity,
add.to.row = list(pos = as.list(rws), command=col))
print(xtable(mydata, caption="Test"), booktabs = TRUE,
include.rownames = FALSE, caption.placement = "top",
sanitize.colnames.function = identity,
add.to.row = list(pos = as.list(rws), command=col))
@
\end{document}
输出:
我的 sessionInfo() 如下:
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.7 formatR_0.9 knitr_1.4.1 stringr_0.6.2 tools_3.0.1