Skip to content

Conversation

yihui
Copy link
Contributor

@yihui yihui commented May 7, 2023

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.')
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: more manual control of figure/table caption numbering
1 participant