1

I've got an .Rmd I need to output using the word_document2 format with R bookdown. It has a .docx template which works fine for heading styles etc.

However, it appears that the figure/table captions are output using the "normal" style, so I can't control the font, size etc. on them as a group and am having to go through after the fact and change them all by hand. Is there a way to get bookdown to designate them to use Word's "caption" style, or alternatively to specify a custom style for them?

user3757897
  • 316
  • 2
  • 13
  • Can you provide a minimal reproducible example please? – Weihuang Wong May 30 '18 at 17:09
  • Sorry - of course I should have done this in the first place. In making one I found the answer, which I've posted below. I can still include the example, but not sure if it's helpful anymore? – user3757897 May 31 '18 at 13:19

2 Answers2

2

In your YAML header for your .Rmd, you can specify a Word doc to use as the basis for all formatting. Your rendered word doc will pick up all the styles from this reference_docx and apply them to your output:

---
title: "Example .Rmd"
output:
  word_document:
    toc: yes
    reference_docx: word-styles-reference-01.docx
theme: hpstr
fontsize: 11pt
---

The Word file that I am using for styles is here: https://drive.google.com/open?id=1gSyE22hJbGdsTj6C-RWBTnyBVnG0XwB3

mysteRious
  • 4,102
  • 2
  • 16
  • 36
  • I had specified a `reference_docx`, yes - the issue was with the reference `.docx` itself, which I've posted in an answer. – user3757897 May 31 '18 at 13:21
2

In trying to make a reproducible example, I found the problem (apologies for not including an example in the first place).

The issue wasn't with the .Rmd, but the reference .docx itself. It had a "Caption" style, but for some reason it didn't have "Image Caption" or "Table Caption" styles, which is what markdown was looking for. I copied those styles over from another Word document according to these instructions, and now it works fine.

user3757897
  • 316
  • 2
  • 13