ms-wordrstudioknitrr-markdownblank-line

Add Blank Line to Word Output RMarkdown


Good day.

I am trying to create a conference abstract submission using a rmarkdown file which exports to a word document. I am trying to find a way to insert a blank line in the outputted word document. I have found that a line break can be inserted by adding two blank spaces at the end of a markdown file, however, this trick does not work when you simply want a blank line. Below is example code

  ---
title: "HERE IS THE TITLE OF MY ABSTRACT"
output:
  word_document:
    reference_docx: draft-styles.docx
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, include=FALSE, cache=FALSE, echo=FALSE}
library(rmarkdown)
```


Authors: John H. Curry^1^, Kathy S. James^1^, Patrick S. Curry^1^
Affiliations: ^1^University of Somewhere 

*Presenting author information*  
Name: John H. Curry 
Email: curry@umed.edu  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  


*Coauthor #2*  
Name: Kathy S. James  
Email: james@umed.edu 
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

*Coauthor #3*  
Name: Patrick S. Curry 
Email: curry2@umed.edu  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  


## Introduction
Here is where I write my introduction....

## Methods
Here is where I write my methods

## Results
Here is where I write my results...

## Discussion
Here is where I write my discussion

When I knit the document, sadly its a little clustered. Below I've added a picture with the current output (left) and what I would like it to look like (right). img

I have read through forums and I have yet to see a solution for this when using a word document. I would appreciate any suggestions.

Thank you


Solution

  • you can use \newline in the Rmd file as follows:

    ---
    title: "HERE IS THE TITLE OF MY ABSTRACT"
    output:
      word_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ```{r, include=FALSE, cache=FALSE, echo=FALSE}
    library(rmarkdown)
    ```
    
    
    Authors: John H. Curry^1^, Kathy S. James^1^, Patrick S. Curry^1^
        Affiliations: ^1^University of Somewhere
    
    \newline
    
    *Presenting author information*
        Name: John H. Curry
    Email: curry@umed.edu
    Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada
    
    \newline
    
    *Coauthor #2*
    Name: Kathy S. James
    Email: james@umed.edu
    Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada
    
    \newline
    
    *Coauthor #3*
    Name: Patrick S. Curry
    Email: curry2@umed.edu
    Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada
    
    \newline
    
    ## Introduction
    Here is where I write my introduction....
    
    \newline
    
    ## Methods
    Here is where I write my methods
    
    \newline
    
    ## Results
    Here is where I write my results...
    
    \newline
    
    ## Discussion
    Here is where I write my discussion
    

    In case you are going to ask next, newpage is slightly harder. You will need to create a new style in word for Heading 5 (for e.g.) which auto starts on a new page and in your Rmd file you will use heading 5 as your new line. there are quite a number of resources online regarding this though.