I am attempting to write a document using RMarkdown v2 (see below) and then knit this to MSWord using "Knit Word" within RStudio (v 0.8.1091) (knitr v1.8). I have modified the normal style in a docx document that was created through knitting such that text with the normal style will be double-spaced and the first line of the paragraph will be indented. I included this docx file in reference_docx in the YAML header. This works fine except that the R code is also double-spaced with the first line indented (see below). I had assumed that the code chunk was a different style that I could alter but I have not yet determined what that style is.
So, how can I change the main text in my resulting MSWord file without changing the R code chunk style?
My RMarkdown document looks like this ...
---
title: "Chapter XX: XXXXX"
author: "Derek H. Ogle"
output:
word_document:
highlight: tango
reference_docx: CSS.docx
---
R code can be shown in a box
```{r}
tmp <- rnorm(100)
summary(tmp)
```
R results can be included in a dynamic sentence, like this one that shows that the mean of the temporary data.frame is `r round(mean(tmp),2)` and the standard deviation is `r round(sd(tmp),2)`.
The resulting Word document looks like this ...

Thank you in advance for your help.
Open your CSS.docx in Word, search for the style named SourceCode. Then edit this style to have single line spacing.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With