Re: How to break line in column title to be (S)weaved?

Jan van der Laan <[email protected]> Fri, 27 Mar 2026 14:56:27 +0100
Newsgroups gmane.comp.lang.r.general
Message-ID <[email protected]>
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]]
> 
> ______________________________________________
> [email protected] 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.