unhcr-dataviz / unhcrdown

UNHCR branded templates for R Markdown
https://unhcr-dataviz.github.io/unhcrdown/
Other
9 stars 12 forks source link

TOC and number_sections in `docx_simple` does not work #30

Closed Edouard-Legoupil closed 1 year ago

Edouard-Legoupil commented 1 year ago

In https://vidonne.github.io/unhcrdown/reference/docx_simple.html

I was trying to add the table of content - as explained here: https://ardata-fr.github.io/officeverse/officedown-for-word.html#toc

by adding

# Table of content

```{r}
block_toc()

Ideally it would be great to also have a parameter to number sections like in

  word_document: 
    toc: yes
    toc_depth: 2
    number_sections: yes
vidonne commented 1 year ago

I tried the approach you mentioned and it did create a table of content (see screenshot below) but the numbered sections doesn't work as it's not part of the block_toc() function from the officer package.

On your other point, we could add it as parameters to the unhcrdown::docx_simple call but you can also pass parameter for the depth of the TOC directly in the block_toc function, e.g. block_toc(level = 2). There might be some possibilities with the following run_autonum() function but will require some experimentations.

Now with the development of Quarto might be worth looking that way as it already includes these possibilities and will offer more flexibilities.

Again, for the time being for rmd documents, see more details on what can be parametrized in the officer package doc.

image
Edouard-Legoupil commented 1 year ago

strange -- did re-install and tried again - below is what I get screen-2023-01-24-11-05-09

vidonne commented 1 year ago

Make sure to click yes on the update file popup when opening the file see here. Maybe that's the issue but works on my side. Also don't forget to put echo=FALSE in the code chunk parameter to avoid the code box.

Edouard-Legoupil commented 1 year ago

Hello - so we can close this - indeed the TOC is there - but I did not get the pop up so had to manually do the update -