Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

latex

knitr

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,

enter image description here

like image 991
Eric Fail Avatar asked Dec 13 '25 10:12

Eric Fail


2 Answers

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}"

like image 148
David Scott Avatar answered Dec 16 '25 08:12

David Scott


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}
like image 45
Dieter Menne Avatar answered Dec 16 '25 08:12

Dieter Menne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!