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

Make possible sequential numbering of reference with section numbering activated #948

Closed
elfunesto opened this issue Sep 12, 2020 · 7 comments · Fixed by #1226
Closed

Make possible sequential numbering of reference with section numbering activated #948

elfunesto opened this issue Sep 12, 2020 · 7 comments · Fixed by #1226
Labels
feature a feature request or enhancement next to consider for next release
Milestone

Comments

@elfunesto
Copy link

When using bookdown (single document), if I set both section_numbering = 'yes' and fig_caption = 'yes', the figures are numbered X.2 (where X is the section number). If section_number = 'no', the figures are numbered sequentially (Fig 1, 2 ...), but sections numbers are lost.

Is there a way to get figures numbered sequentially without losing the section numbers? In the example below, I would like to have both the sections figures numbered as 1 and 2.
I had posted this question on stackoverflow and I was suggested to fill an issue.

Thank you.

---
output: 
  bookdown::html_document2: 
    fig_caption: yes
    number_sections: yes
---
# header 1
Reference example: \@ref(fig:plotcars):
```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```
# header 2
Reference example: \@ref(fig:plotcars2):
```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```

By filing an issue to this repo, I promise that

  • [x ] I have fully read the issue guide at https://yihui.org/issue/.
  • [x ] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [ x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@atusy
Copy link
Collaborator

atusy commented Sep 14, 2020

I think we can implement this feature by adding an argument whose value is passed to the global argugment of the internal resolve_refs_html function.
Maybe global_refs is the potential name of the argument with !number_sections as a default value in terms of backward compatibility.

x = resolve_refs_html(x, global = !number_sections)

BTW, this feature might be useful in word_document2 when users also want fine controls on fomrats of section numbering via template via reference_docx.
Currently, section-level figure numbering requires word_document2(number_sections = TRUE), which separates section numbers and section contents by a tab.
I prefer a space, but the tab is the choice of pandoc...
global_refs would provide more flexibility for word_dcoument2.

@cderv cderv added feature a feature request or enhancement and removed enhancement labels Mar 15, 2021
@cderv
Copy link
Collaborator

cderv commented Mar 31, 2021

Duplicate of #1057

@cderv cderv marked this as a duplicate of #1057 Mar 31, 2021
@cderv cderv added the next to consider for next release label Mar 31, 2021
@cderv cderv changed the title Suggestion: bookdown figure number formatting: both sequential numbering and section numbering Make possible sequential numbering of reference with section numbering activated Mar 31, 2021
@yihui yihui added this to the v0.23 milestone Apr 15, 2021
@RLesur
Copy link
Collaborator

RLesur commented May 3, 2021

For the record, for HTML documents, pagedown uses this solution to fix a similar issue (rstudio/pagedown#184).

@yihui
Copy link
Member

yihui commented Aug 11, 2021

I just added a new argument global_numbering. You can test the development version via

remotes::install_github('rstudio/bookdown')

Example:

---
output: 
  bookdown::html_document2: 
    fig_caption: true
    number_sections: true
    global_numbering: true
---

# header 1

Reference example: \@ref(fig:plotcars):

```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```

# header 2

Reference example: \@ref(fig:plotcars2):

```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```

Thanks!

@daviesmd
Copy link

daviesmd commented Sep 6, 2021

I'd like to have my pdf document number figures and tables in the format 1.1, 1.2 etc where the first number is the chapter or section number. The only solution I've found is here: https://stackoverflow.com/questions/53863797/r-markdown-pdf-document2-pdf-figure-and-table-numbers-by-section
Is there a better way?

@yihui
Copy link
Member

yihui commented Sep 7, 2021

@daviesmd I don't know if there is a better way. The solution on Stack Overflow doesn't seem to be bad to me.

@github-actions
Copy link

github-actions bot commented Mar 9, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement next to consider for next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants