pander does not include table numbering when used with bookdown::html_document2. Did I miss some option?
---
title: "Pander Table Numbering"
output: bookdown::html_document2
---
# Chapter 1
```{r}
library(knitr)
library(pander)
# Table 1.1
kable(head(iris), caption = "Iris with kable")
# Another Table 1.1 (ok, same chunk = same table)
kable(head(mtcars), caption = "Mtcars kable")
```
```{r}
# No table number
pander(head(iris), caption = "Iris with pander")
```
```{r}
# Table 1.2
kable(head(mtcars), caption = "Mtcars kable")
```
First, I am an extremely grateful user of bookdown
!
I have tried to achieve the same thing using pander
instead of kable
. The reason for this is that kable
or kableExtra
do not render markup text in tables of pdf output, which is a huge current drawback... So for pdf output, kable
will not render things like literature references such as @smith2018-so
or *italic*
and so on... which is a pain. Hopefully, a patch will be provided soon. To take the same code above, I was able to have the referencing work with pander
provided several changes in the code above. Another thing about kable
, one must add longtable=T
otherwise the table floats down to the bottom of a page in pdf output.
First I added documentclass: article
in the YAML, and then I named the the code chunks. But the thing that really make it work in pander is by changing the caption to caption = '(\\#tab:chunkname) Iris with pander')
. The trick was to add the double \\
which I could not find in the bookdown
reference. So in the end, a code that worked for both html and pdf outputs is :
---
title: "Pander Table Numbering"
documentclass: article
output:
bookdown::html_document2: default
bookdown::pdf_document2: default
---
# Chapter 1
Table \@ref(tab:TabKable1)
```{r "TabKable1", results='asis'}
library(knitr)
library(pander)
# Table 1.1
knitr::kable(head(iris), caption = 'Iris with kable', longtable =T)
# Another Table 1.1 (ok, same chunk = same table)
#kable(head(mtcars), caption = "Mtcars kable")
```
Table \@ref(tab:TabPander1)
```{r "TabPander1"}
# No table number
pander(head(iris), caption = 'Iris with pander')
```
Table \@ref(tab:TabPander2)
```{r "TabPander2"}
# table number this time!!
pander(head(iris), caption = '(\\#tab:TabPander2) Iris with pander')
```
Table \@ref(tab:TabKable2)
```{r "TabKable2"}
# Table 1.2
kable(head(mtcars), caption = "Mtcars kable", longtable=T)