Print.xtable with multi-line header?

I am trying to create a table with a header that contains a similar gap. I'm not too ambitious here, and I don't care if I just broke very long lines or just had a two-line header in general.

dat <- matrix(round(rnorm(9, 20, 10)), 3, 3) colnames(dat) <- c("some very long colname","short","another toooooooolong colname") require(xtable) m <- xtable(dat) print(m, floating=FALSE, hline.after=NULL, size="\\footnotesize", tabular.environment="tabular", add.to.row=list(pos=list(-1,0,nrow(m),0 ), command=c('\\toprule ', '\\midrule ', '\\bottomrule', '\\\\ \\rowcolor[gray]{.9}' ) ) ) 

Is there a way for the line to break the header because my table no longer fits the page, although I already use landscape . Some kind of sanitize.rownames trick? Tucked around with \shortstack , but couldn't get it to go ...

+6
source share
1 answer

(Writing my comment in the correct answer)

In the xtable call xtable you can specify various alignment arguments, one of which is a parbox fixed width in which the text will be wrapped. This is indicated by p{1in} , where the value indicated in braces is equal to the width of the field (column). You must manually specify this (instead of adapting it to the available space), but this gives you one option for wrapping text.

+6
source

All Articles