Split xtable ouput into sub tables

后端 未结 1 718
暗喜
暗喜 2021-01-04 20:51

Have a question on using xtable with Sweave when there are multiple columns. A table I am working on has about 25 columns and 5 rows. The exact number of columns is not know

相关标签:
1条回答
  • 2021-01-04 21:43

    Here's an example of this from ?latex.table.by in the taRifx package. You can brew something similar using longtable in LaTeX and use the latex.table.by code as a prototype.

    my.test.df <- data.frame(grp=rep(c("A","B"),10),data=runif(20))
    library(xtable)
    latex.table.by(my.test.df)
    #   print(latex.table.by(test.df), include.rownames = FALSE, include.colnames = TRUE, sanitize.text.function = force)
    #   then add \usepackage{multirow} to the preamble of your LaTeX document
    #   for longtable support, add ,tabular.environment='longtable' to the print command (plus add in ,floating=FALSE), then \usepackage{longtable} to the LaTeX preamble
    

    Regardless, the longtable package in LaTeX is the key.

    Edit: It appears you have too many columns not too many rows. In that case, first try landscaping just that page.

    In the header:

    \usepackage{lscape}
    

    Around your table:

    \begin{landscape}
    ...
    \end{landscape}
    

    Or just use sidewaystable.

    If your table is too wide to fit in one page, try the supertabular package, which from the description sounds like it might handle breaking over multiple pages based on width (but I've never used it so can't be sure).

    0 讨论(0)
提交回复
热议问题