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

control table and figure seq_id from yaml header or chunk options #71

Open
zilch42 opened this issue May 26, 2021 · 3 comments
Open

control table and figure seq_id from yaml header or chunk options #71

zilch42 opened this issue May 26, 2021 · 3 comments

Comments

@zilch42
Copy link

zilch42 commented May 26, 2021

The issue I am experiencing is that officedown uses different field code SEQ ids for tables and figures than word so if I create a word document with officedown and then make a few table or figure additions manually, they end up belonging to different sequences. This may be a locale thing, I'm not sure. I am using an Australian version of Word.

manually generated in word:
{ SEQ Table * ARABIC }
{ SEQ Figure * ARABIC }

generated by officedown
{SEQ tab * Arabic}
{SEQ fig * Arabic}

I understand the officer has some control over this with run_autonum(seq_id = "fig") but I don't call that directly when using officedown: e.g:

```{r tab.cap='iris', tab.id='iris'}
head(iris)
```

Would it be possible to have options either in the yaml header or chunk options (so that global defaults could be set) for defining which seq_id is used? If this is a locale based issue then it would allow users to define the correct ID for their localized version of word.

E.g.

officedown::rdocx_document:
  base_format: "bookdown::word_document2"
  reference_docx: "template.docx"
  number_sections: FALSE
  tables:
    style: Table_CSIRO
    caption: 
      style: Caption
      pre: 'Table '
      sep: ' '
      seq_id: Table
    conditional:
      first_row: true
      first_column: true
      last_row: false
      last_column: false
      no_hband: false
      no_vband: true
  plots:
    style: 'Body Text'
    caption: 
      style: Caption
      pre: 'Figure '
      sep: ' '
      seq_id: Figure

If there is already a way of doing this, please forgive me. I have looked everywhere for it.

@davidgohel
Copy link
Owner

Yes, it's a local thing. In France, it's "Table" for example and this is stored in a hidden Word template somewhere in your computer.

You can use knitr chunk option fig.lp (See https://yihui.org/knitr/options/) and officedown is supporting via officer option tab.lp which does not exist with knitr (to my knowledge)

@zilch42
Copy link
Author

zilch42 commented May 28, 2021

Thanks David! that's great to know. I've now got fig.lp working, but I think I found an issue with tab.lp when used in conjunction with flextable. If you knit the following example and look at the field codes generated, the first one uses { SEQ Table * ARABIC } as set in the global chunk options, but the second one which is a flextable uses {SEQ tab * Arabic}

---
bookdown::markdown_document2:
  base_format: officedown::rdocx_document
  reference_docx: "template.docx"
---
  
```{r include=FALSE, warning=FALSE, message=FALSE}
# load libraries
library(knitr)
library(officedown)
library(officer)
library(flextable)
library(tidyverse)

# global chunk options
knitr::opts_chunk$set(fig.lp = "Figure", tab.lp = "Table")
```

This is \@ref(tab:mtcars)

```{r tab.cap='MT Cars', tab.id='mtcars'}
mtcars %>% head(6)
```

This is flextable \@ref(tab:mtcarsflex)

```{r tab.cap='MT Cars', tab.id='mtcarsflex'}
mtcars %>% head(6) %>% flextable()
```

flextable 0.6.6
officedown 0.2.3.001
officer 0.3.18
R 4.0.5

@davidgohel
Copy link
Owner

I don't think the example you provided is valid. I did not run it, I am sure it will produce an HTML file.

I will investigate that later then.

Note tab.lp is not documented as it was not supposed to be used by users. Now I need to go fix an issue with flextable because you want to change it ;)

davidgohel added a commit to davidgohel/flextable that referenced this issue Jul 15, 2021
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

No branches or pull requests

2 participants