繁体   English   中英

来自修正的xtable功能的独立乳胶台

[英]Standalone latex table from amended xtable function

我正在尝试创建一个自动R函数,它可以通过外部Latex程序创建一个可以运行的乳胶文件(不需要对Latex代码进行任何进一步的修改)。 我知道KnitR和Sweave,但我需要更简单的东西。 基本上对于任何可以通过xtable打印的对象我想添加

%A1在顶部

\documentclass{article}
\pagestyle{empty}
\begin{document}

最后%A2

\end{document}

这意味着我可以运行我的分析并(当我需要时)创建一个可以由基于Latex的程序操作的外部文件。 我对将所有表放入一个文档并不感兴趣,但我希望它们分开(因此需要\\ begin {document}和\\ end {document}。我一直在尝试使用add.to.rows(xtable函数)但我无处可去。

例:

data(tli)
tli.table <- xtable(tli[1:10,])
digits(tli.table)[c(2,6)] <- 0
print(tli.table,floating=FALSE)

你如何添加A1和A2,结果是:

\documentclass{article}
 \pagestyle{empty}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{rrlllr}
  \hline
 & grade & sex & disadvg & ethnicty & tlimth \\ 
  \hline
1 &   6 & M & YES & HISPANIC &  43 \\ 
  2 &   7 & M & NO & BLACK &  88 \\ 
  3 &   5 & F & YES & HISPANIC &  34 \\ 
  4 &   3 & M & YES & HISPANIC &  65 \\ 
  5 &   8 & M & YES & WHITE &  75 \\ 
  6 &   5 & M & NO & BLACK &  74 \\ 
  7 &   8 & F & YES & HISPANIC &  72 \\ 
  8 &   4 & M & YES & BLACK &  79 \\ 
  9 &   6 & M & NO & WHITE &  88 \\ 
  10 &   7 & M & YES & HISPANIC &  87 \\ 
   \hline
\end{tabular}
\end{table}
\end{document}

我一开始就卡住了:

bottom <- list();bottom$pos<- list()
bottom$pos[[1]] <- c(nrow(x))
bottom$command  <-c("\\end{document} \n")
print(xtable(tli[1:10,]),add.to.row=bottom)

我需要\\ end {document}在最后但是如果我改变了

bottom$pos

bottom$pos[[1]] <- c(nrow(x)+3)

我收到一个错误。 我也没有包括顶部(A1-见上文)。

理想情况下,我希望代码尽可能通用,以便它可以应用于任何xtable输出(例如anovas,sideway tables等...)。

有任何想法吗?

非常感谢

catprint.xtable函数都有一个'append'参数:

wrapLatex <- function(dat,fil, ...) {
     cat(c("\\documentclass{article}\n",
           "\\pagestyle{empty}\n",
           "\\begin{document}\n"), file=fil)
   print(dat, file=fil, append=TRUE, ...)
      cat("\\end{document}\n", file=fil, append=TRUE) }
wrapLatex(tli.table, fil="~/test")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM