rknitrpander

numbering of split table in pander


using R + knitr + pander, for some reason a wide table that is split into more than two subtables gets more than one table number in the resulting pdf.

For example, running the R Script test.R:

library(pander)
dat <- data.frame(a = rep(1:2, 13), b = paste0(LETTERS, "longtext"))
pander(table(dat$a, dat$b))

via rmarkdown::render("test.R", "pdf_document") produces a pdf with the table split into 5 pieces, the first 4 pieces numbered Table 1 to Table 4, only the last piece is unnumbered. This only happens when the table is split into more then 2 pieces.

Since it is just one table, I would like to have only one number for it in the output (just as it is when a table is split into 2 pieces). How can this be accomplished?

Regards, Henrik


Solution

  • What about disabling the auto-generated "Table continues below" caption?

    > panderOptions('table.continues', '')
    > pander(table(dat$a, dat$b), caption = 'foobar')
    
    -----------------------------------------------------------------------
     Alongtext   Blongtext   Clongtext   Dlongtext   Elongtext   Flongtext 
    ----------- ----------- ----------- ----------- ----------- -----------
         1           0           1           0           1           0     
    
         0           1           0           1           0           1     
    -----------------------------------------------------------------------
    
    Table: foobar (continued below)
    
    
    -----------------------------------------------------------------------
     Glongtext   Hlongtext   Ilongtext   Jlongtext   Klongtext   Llongtext 
    ----------- ----------- ----------- ----------- ----------- -----------
         1           0           1           0           1           0     
    
         0           1           0           1           0           1     
    -----------------------------------------------------------------------
    
    
    -----------------------------------------------------------------------
     Mlongtext   Nlongtext   Olongtext   Plongtext   Qlongtext   Rlongtext 
    ----------- ----------- ----------- ----------- ----------- -----------
         1           0           1           0           1           0     
    
         0           1           0           1           0           1     
    -----------------------------------------------------------------------
    
    
    -----------------------------------------------------------------------
     Slongtext   Tlongtext   Ulongtext   Vlongtext   Wlongtext   Xlongtext 
    ----------- ----------- ----------- ----------- ----------- -----------
         1           0           1           0           1           0     
    
         0           1           0           1           0           1     
    -----------------------------------------------------------------------
    
    
    -----------------------
     Ylongtext   Zlongtext 
    ----------- -----------
         1           0     
    
         0           1     
    -----------------------