What LaTeX package to use with knitr to get more table-control? tabu?

こ雲淡風輕ζ 提交于 2020-01-02 08:23:04

问题


I’m writing a longer table with knitr using xtable and the tabular.environment='longtable' in the longtable package when printing 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!