Repeat headers when using xtable with longtable option

后端 未结 2 1664
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 01:11

Is there a way to repeat the top row / set headers when generating an xtable with a longtable option ?

For eg., if I have

tableSb <- xtable(df, captio         


        
2条回答
  •  梦谈多话
    2021-02-14 01:54

    In order to accomplish this, you'll need to use the add.to.row option of the print function (run ?print.xtable for more information).

    Try this (adapted from https://r-forge.r-project.org/tracker/?func=detail&atid=4864&aid=1627&group_id=1228)

    addtorow          <- list()
    addtorow$pos      <- list()
    addtorow$pos[[1]] <- c(0)
    addtorow$command  <- c(paste(
      "\\hline \n",
      "\\endhead \n",
      "\\hline \n",
      "{\\footnotesize Continued on next page} \n",
      "\\endfoot \n",
      "\\endlastfoot \n",
      sep=""))
    x.big <- xtable(
      x,
      label = "tabbig",
      caption = "Example of longtable spanning several pages")
    print(
      x.big,
      tabular.environment = "longtable",
      floating = FALSE,
      include.rownames = FALSE,  # because addtorow will substitute the default row names 
      add.to.row = addtorow,     # this is where you actually make the substitution
      hline.after=c(-1))         # because addtorow will substitute the default hline for the first row
    

    It's a bit clumsy of a solution, but at least it'll provide you with plenty of customization.

提交回复
热议问题