[R] How to break line in column title to be (S)weaved?
Jan van der Laan
rhe|p @end|ng |rom eoo@@dd@@n|
Fri Mar 27 15:14:32 CET 2026
Another trick would be to a another row to the headers:
print(xtable(iris[1:10, ]),
add.to.row = list(pos = list(0),
command = "& Second & Row & Of & Headers & Species\\\\\n" ))
On 3/27/26 2:56 PM, Jan van der Laan wrote:
> Haven't tried this, but you might be able to use the tabularx output
> which supports the X column type that will stretch the column width and
> wrap the contents. So, something like:
>
> print(xtable(iris[1:10, ], align = "rrrrrX"),
> tabular.environment = "tabularx", width = "\\textwidth")
>
>
> HTH,
> Jan
>
>
> On 3/21/26 12:16 PM, iagogv via R-help wrote:
>> Hi all,
>>
>> I am doing a LaTeX document with R, so .Rnw file, which I 'Sweave' to
>> get the .tex file I will 'LaTeX' to .pdf.
>>
>> In that document, I want to include a small data.frame, let's call
>> `data`, therefore I use the xtable package and include something like
>>
>> <<echo=FALSE,results=tex>>=
>> print(xtable(data))
>> @
>>
>> One of the names of data is too long, let's say 'This column has a long
>> name' and I want it to be displayed in two rows. Therefore, among other
>> things, in the tex file the two rows should be separated by '\\', so it
>> should appear, for example, as 'This column\\ has a long name'.
>>
>> If in the .Rnw file I include \\ in the name, it is (S)weaved to
>> $\backslash$. I I include \textbackslash, Sweave returns extbackslash.
>>
>> Therefore, my question is how can I do to get column name in multiple
>> rows. I am open to use other packages than xtable, but I want this
>> working with Sweave (so no Rmarkdown/knitr solutions, please).
>>
>> Thanks!
>>
>> Iago
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide https://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list