问题
I’m writing a longer table with knitr using xtable
and the tabular.environment='longtable'
in the longtable package when print
ing them in my .Rnw
-file, problem is that I can’t control the longtable environment enough.
I have some text I would like to have left-justified and hyphenated in a certain way inside the table (i.e. I have some cells with quite a lot of text)
Any advice on how I could do this? What packages would you recommend? Anyone tried the tabu
package?
What I am mainly looking for is a way to justify my text in a nice way inside my table. Something along the lines of this,

回答1:
I can confirm (as maintainer of xtable
) that no backslashes are needed. I have updated the documentation of xtable
on R-Forge.
A couple of notes:
There is an example of the use of fixed width alignments in the xtable
Gallery vignette.
Also, a slightly simpler specification works, namely, align = "llp{5cm}"
回答2:
xtable
has parameter align
; for your example, try
align=c("l","l","l","p\{5cm\"})
Edited (after checking @Alex A. comment): The \before the last " was definitively wrong, but this time I checked carefully. Looks like the following version without any backslashes is correct. I will report the error in the docs to the package author.
\documentclass{article}
\begin{document}
<<a, results='asis'>>=
library(xtable)
x = data.frame(a=1:10,
b=rep("This is a very long text that takes up to much space",10),
stringsAsFactors = FALSE)
xt = xtable(x, align=c("l","l","p{5cm}"))
print(xt, include.rownames=FALSE)
@
\end{document}
来源:https://stackoverflow.com/questions/13664365/what-latex-package-to-use-with-knitr-to-get-more-table-control-tabu