13.7 Create Word template file

To make sure tables always export with a suitable font size, you may edit your Word file but only to create a new template. You will then use this template to Knit the R Markdown document again.

In the Word document the first example outputted, click on a table. The style should be compact: Right-click > Modify… > font size = 9

Alter heading and text styles in the same way as desired. Save this as colonTemplate.docx (avoid underscores in the name of this file). Move the file to your project folder and reference it in your .Rmd YAML header, as shown below. Make sure you get the spacing correct, unlike R code, the YAML header is sensitive to formatting and the number of spaces at the beginning of the argument lines.

Finally, to get the figure printed in a size where the labels don’t overlap each other, you will have to specify a width for it. The Chunk cog introduced in the previous chapter is a convenient way to change the figure size (it is in the top-right corner of each grey code chunk in an R Markdown document). It usually takes some experimentation to find the best size for each plot/output document, in this case we are going with fig.width = 10.

Knitting Example 2 here gives us Figure 13.2B). For something that is generated automatically, it looks awesome.