Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function to customize caption numbering #1427

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yihui
Copy link
Member

@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