R officedown::rdocx_document, templates and styles

1.6k Views Asked by At

I am trying to nut out how to use a company word document as a rdocx_doxument template for R markdown using the officedown package.

---
title: Company Report Title 
author: Ross 
date: 3/3/2022 
output: 
  officedown::rdocx_document: default
---
  

# Introduction

Identifying default table and figure caption styles


```{r plot, fig.cap="My plot caption"}
plot(cars)
```


# Table

```{r, message = FALSE, warning=FALSE}
library(flextable)
cars |> head(6) |> flextable() |>
  set_caption("Caption for table")
```

The style from this example gives an 'Image Caption' style for the plot and a 'Table Caption' style for the table.

Now try using the company reference template

---
title: Company Report Title 
subtitle: Report subtitle 
author: Ross 
date: 3/3/2022 
output: 
  officedown::rdocx_document: 
    reference_docx: company_report_template.docx
    mapstyles:
      Image Caption: ['Caption']
      Table Caption: ['Caption']
      Title: ['CoverTitle']
---
  

# Introduction

How to use mapstyles to avoid redefining company word template styles.


```{r plot, fig.cap="My plot caption"}
plot(cars)
```


# Table

```{r, message = FALSE, warning=FALSE}
library(flextable)
cars |> head(6) |> flextable() |>
  set_caption("Caption for table")
```

In the word template file there is a style defined for both figure and table captions called 'Caption' and a style called 'CoverTitle' for the Title.

The rendering error message is

Error: could not find style "Caption". In addition: Warning message: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead. Execution halted

The template file does have a 'Caption' style defined.

Wondered if someone can help me fathom this out?

I am very reluctant to change the styles in the company word template file.

Thanks

Screenshot of rmarkdown header, render error and word template file showing style

0

There are 0 best solutions below