我在 R-Studio 中处理一个文件,它运行得很好(大约有两页的输出确实有效)。但是当我尝试用新表添加它时,我不断得到:
> "Running pdflatex.exe on playerArbitrationProfile.tex...failed"
问题出在打印表格的 R 代码中。以下是我目前所拥有的:
<<echo=False,results=tex>>=
print(xtable((transactions),align=c(rep('c',3),rep('c',ncol(transactions)-2))),sanitize.colnames.function=bold,include.rownames=FALSE,latex.environments = "left",hline=NULL,floating=FALSE, size="\\fontsize{2pt}{3pt}\\selectfont",add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),tabular.environment = 'tabularx', width="7in")
@
该表(内置于 R 中)有三列:交易日期(字符)、交易团队(字符)和交易描述(字符)。该表有 17 条观察结果。交易描述列略长,但我认为长度不是问题,因为我尝试在没有该列的情况下运行它,但没有任何区别(另外,如果有人能提供一种简单的方法让文本在第三列中换行,我将不胜感激)。有人看到上述代码中存在任何问题,导致我的报告无法运行吗?
谢谢!
答案1
我认为问题可能是你使用了Sweave
(results=tex
)语法,但是使用knitr
(语法应该是results='asis'
)
无论如何,以下内容对我来说是编译的
\documentclass[landscape]{article}
\usepackage{tabularx}
\usepackage{booktabs}
<<data, echo=FALSE>>=
transactions <- as.data.frame( list(
date = paste("date" , 1:17) ,
team = paste("team" , 1:17),
decription = paste('description' , 1:17)
) )
@
<<setup, echo=FALSE>>=
library(xtable)
bold <- function(x) {
paste0('\\textbf{' , x , '}')
}
@
\begin{document}
<<table, echo=FALSE , results='asis'>>=
print(
xtable(transactions,align=c(rep('c',3),rep('c',ncol(transactions)-2))) ,
sanitize.colnames.function = bold,
include.rownames=FALSE,
latex.environments = "left",
hline=NULL,
floating=FALSE,
size="\\fontsize{2pt}{3pt}\\selectfont",
add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),
tabular.environment = 'tabularx',
width="7in"
)
@
\end{document}
编辑:工作 Sweave 版本:
\documentclass[landscape]{article}
\usepackage{tabularx}
\usepackage{booktabs}
<<data, echo=FALSE>>=
transactions <- as.data.frame( list(
date = paste("date" , 1:17) ,
team = paste("team" , 1:17),
decription = paste('description' , 1:17)
) )
@
<<setup, echo=FALSE>>=
library(xtable)
bold <- function(x) {
paste0('\\textbf{' , x , '}')
}
@
\begin{document}
\SweaveOpts{concordance=TRUE}
<<table, echo=FALSE , results=tex>>=
print(
xtable(transactions,align=c(rep('c',3),rep('c',ncol(transactions)-2))) ,
sanitize.colnames.function = bold,
include.rownames=FALSE,
latex.environments = "left",
hline=NULL,
floating=FALSE,
size="\\fontsize{2pt}{3pt}\\selectfont",
add.to.row=list(pos=list(1:(nrow(transactions)),0), command=c( '\\midrule\n','\\toprule\n')),
tabular.environment = 'tabularx',
width="7in"
)
@
\end{document}