自动换线编织xtable(R / Latex)

时间:2016-07-15 14:15:24

标签: r latex knitr

我试图在xtable生成的PDF文档的每一行用knitr做长句。

我试过了:

<<echo=F,results="asis",command=NA>>=
df<-c("This is a very very very very very very very very very very very very very very very very very very very very long line",
"Another very very very very very very very very very very very long line")
df<-as.data.frame(df)
xtab <- xtable(df)
print.xtable(xtab,sanitize.text.function=function(x){x})
@

但我的结果是:

enter image description here

如你所见。我的xtable溢出页面,因为我的行太长了。有人能帮助我吗?

PS:我无法使用{tabular},因为我的数据框的长度取决于闪亮的应用用户的输入。

1 个答案:

答案 0 :(得分:2)

看看对齐功能:

<<echo=FALSE,results=tex>>=
library(xtable)
df<-c("This is a very very very very very very very very very very very very very very very very very very very very long line",
"Another very very very very very very very very very very very long line")
df<-as.data.frame(df)
xtab <- xtable(df)
align(xtab) <- "|lp{6cm}|"
print.xtable(xtab,sanitize.text.function=function(x){x})
@

您可以像使用任何其他LaTeX表一样更改列对齐方式。这些资源可能对您有所帮助:

  1. xtable gallery
  2. LaTeX Wikibook