使用R xtable在乳胶表中的行之间添加水平线

ale*_*lex 7 latex r xtable

我有这样的乳胶表生成代码示例

df<-data.frame(name=rep(letters[1:7],each=24),salary=runif(24*7,100,200))
lst<-tapply(df$salary,df$name,matrix,nrow=4,byrow=T)
xlst<-lapply(lst,xtable)
Run Code Online (Sandbox Code Playgroud)

现在我想在每个表中的每一行之后自动引入\ hdashline,并且在R代码之间的表之间还有一个\ vspace {2em} Wat我试过这个

for(i in seq_along(lst)){
  addtorow[i] <- list(pos = list(seq_len(nrow(lst[[i]])-1)),
                      command = "\\hdashline \n")
}
Run Code Online (Sandbox Code Playgroud)

扫描更改我需要进行循环..它适用于我申请单个表但不能在for循环中工作...任何帮助非常感谢...

And*_*rie 11

不要使用循环,而应考虑将现有print.xtable功能与粘贴结合使用.

  1. hdashlines: 考虑使用print.xtable参数.例如,有一个参数hline.after可以控制表格线之间的水平线.

  2. vspace:这可能更简单paste.

例如:

library(xtable)
df <- data.frame(name=rep(letters[1:3],each=24),salary=runif(24*3,100,200))
lst <- tapply(df$salary,df$name,matrix,nrow=4,byrow=T)
xlst <- lapply(lst,function(x)print(xtable(x), hline.after=1:nrow(x)))
xlst <- lapply(xlst, paste, "\\vspace{2em}")
xlst
Run Code Online (Sandbox Code Playgroud)

[1]"通过xtable 1.5-6包在R 2.13.1中生成的%乳胶表\n%Tue Aug 23 13:36:41 2011 \n\begin {table} [ht] \n\begin {center} \n\begin {tabular} {rrrrrr} \n&1&2&3&4&5&6 \\ \n 1&158.66&115.81&106.70&128.78&157.43&191.01 \\ \n\hline \n2&159.09& 172.31&153.93&127.91&106.93&147.95 \\ \n\hline \n3&135.65&139.45&192.90&108.78&186.52&164.10 \\ \n\hline \n4&190.10&154.39&124.91&199.24&161.99&167.61\\ \n
\hline \n\end {tabular} \n\end {center} \n\end {table} \n\vspace {2em}"


有关?print.xtable详细信息,请参阅 如果hline.after对于您的目的不够灵活,那么请查看add.to.row您可以指定要添加的位置和确切元素类型的位置.