I've been trying to create a table with a header that contains a like break. I am not too ambitious here and do not really care whether I just break extremely long strings or just have 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 to line break the header, because my table is not fitting on the page anymore, though I use landscape
already. Some sanitize.rownames
based trick? Fiddled around with \shortstack
but could not get it to go...
(Writing my comment up into a proper answer)
In the call to xtable
, you can specify various alignment arguments, one of which is a parbox
of a fixed width in which text will be wrapped. That is specified with p{1in}
where the value specified within the braces is how wide the box (column) will be. You have to manually specify this (rather than have it adapt to the available space), but it does give you one option for wrapping text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With