bookdown
bookdown copied to clipboard
Add a helper function to customize caption numbering
This is supposed to close #855, but it has a technical flaw that's not easy to overcome. That is, cross-references to custom caption numbers won't work (see the example below).
Installation
remotes::install_github('rstudio/bookdown#1427')
Example
Create a file _bookdown.yml:
language:
label:
tab: !expr bookdown::number_caption(3, c('Table', 'Supplementary table'))
It means that for tables after the 3rd table, restart the table number from 1, and change the caption label from Table to Supplementary table).
Then an Rmd file under the same directory:
---
title: "Test"
output:
bookdown::html_document2:
global_numbering: true
bookdown::word_document2:
global_numbering: true
---
# Section one
```{r, test-a}
knitr::kable(head(iris), caption = 'One table.')
```
```{r, test-b}
knitr::kable(iris[7:12, ], caption = 'Another table.')
```
# Section two
```{r, test-c}
knitr::kable(iris[7:12, ], caption = 'Another table.')
```
# Supplementary materials
Supplementary table \@ref(tab:test-d) (this number is incorrect).
```{r, test-d}
knitr::kable(head(mtcars), caption = 'Yet another table.')
```