2

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

Henrik
  • 65
  • 4

1 Answers1

1

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     
-----------------------
daroczig
  • 28,004
  • 7
  • 90
  • 124
  • 1
    This _suppressess printing_ of the numbers, which works just fine if this is the only table in the document. However, if other tables follow, suppressing printing isn't enough: if I add `pander(table(1:3), caption = "2nd table")` to my script, this table will be numbered Table 6. I don't know if this is a feature or an issue with pander, but the effect seems a little strange to me. I found a workaround putting latex `$\setcounter{table}{1}$` after the first table. Works, though in documents with many tables it means you have to be careful so that your table numbering won't get messed up... – Henrik Jul 26 '17 at 10:48
  • Well, markdown fits most document editing needs, but once you start facing the limitations, probably it's better to switch to LaTeX :/ Here that could mean using `xtable` instead of `pander` or coming up with a LaTeX macro killing table numbers when there's no caption. – daroczig Jul 26 '17 at 16:23