Flo
Flo

Reputation: 1565

Format text for word output while using rmd template

I want to be able to format the word output (html output or pdf output works fine with html and LaTeX, respectively) while using the papaja template for word.

As an example, let's say I want to start a paper with an epigraph, where the first line contains someone's quote (left-aligned, without indent) and the second line contains the quoted person's name (right-aligned):

example formatting

The following gives me APA formatting thanks to papaja (as desired) and a word document with the styles "left" and "right".

---
title: Test
author:
- name: author
  email: [email protected]
  address: address
  corresponding: yes
output:
  papaja::apa6_word 
---


```{r message = FALSE, warning = FALSE}
knitr::opts_chunk$set(echo = FALSE)
library("papaja")
```


<div custom-style="left">This text should go on the left after editing the styles in word</div>

<div custom-style="right">This text should go on the right after editing the styles in word</div>

When I edit the styles "left" and "right" in the word document, save that document as template.docx and then change my output to include the template as reference (see MWE below), the first lines are correctly formatted (aligned to the left and right). However, as I did not specify that I want to use papaja's apa6_word template, the output is logically not formatted in APA style.

---
title: Test
author:
- name: author
  email: [email protected]
  address: address
  corresponding: yes
output: 
    word_document:
      reference_docx: template.docx
---


```{r message = FALSE, warning = FALSE}
knitr::opts_chunk$set(echo = FALSE)
library("papaja")
```

<div custom-style="left">This text should go on the left after editing the styles in word</div>

<div custom-style="right">This text should go on the right after editing the styles in word</div>

Is there a way to get both? I.e., leave the formatting to papaja::apa6_word but be able to fine-tune some aspects? Hacks specific to this question would already be a help, but as I anticipate to encounter this problem more often, I was wondering whether there was a more general solution?

Upvotes: 1

Views: 905

Answers (1)

crsh
crsh

Reputation: 1716

Great question. With the latest development version of papaja (devtools::install_github("crsh/papaja@devel")) you can provide a custom reference DOCX file to apa6_word. So, in you example, instead of word_document you can use apa6_word:

output:
  papaja::apa6_word:
    reference_docx: template.docx

Upvotes: 1

Related Questions