Add Blank Line to Word Output RMarkdown
Asked Answered
S

3

25

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: [email protected]  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  


*Coauthor #2*  
Name: Kathy S. James  
Email: [email protected] 
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

*Coauthor #3*  
Name: Patrick S. Curry 
Email: [email protected]  
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

Southard answered 5/4, 2017 at 19:20 Comment(0)
E
19

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: [email protected]
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada

\newline

*Coauthor #2*
Name: Kathy S. James
Email: [email protected]
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada

\newline

*Coauthor #3*
Name: Patrick S. Curry
Email: [email protected]
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.

El answered 6/4, 2017 at 0:50 Comment(2)
This is perfect! I was able to get my desired output using a combination of \newline and adding double spaces at the end of lines. For those interested I posted the code that gave me the results I was seekingSouthard
This no longer works for me, however the answer below from @eric krantz worked (<br>) https://mcmap.net/q/526193/-add-blank-line-to-word-output-rmarkdownRosmunda
C
28

I upvoted the answer 2 years ago, but now \newline doesn't work for me. However, <br> works. Make sure you have empty space above and below <br>. Works for charts and code snippet output too.

    ---
title: "Word/knitr linefeed test"
author: "E Krantz"
date: "7/28/2020"
output: word_document
---

Here are results with no assisted new line.

How to new line in knitr with MSWord? Test newline:

\newline  \newline

That doesn't work. Test br:
<br>
That does not work. Test br with linebreak after:
<br>

No changes. Test br with linebreak before:

<br>
This puts a space before this sentence. Test br with break before and after.

<br>

That works! Double br:

<br>
<br>

Same as single br. How about double br with a line break between each?

<br>

<br>

That works!

Here are the results: Results

Cognation answered 29/7, 2020 at 14:52 Comment(2)
this solution works !! thanks for writing this answer you saved meWillingham
It works - and thank you for including the detail about space before and after - that would have been easy to miss.but geez! It seems like there should be a better way.Sanjuanitasank
E
19

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: [email protected]
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada

\newline

*Coauthor #2*
Name: Kathy S. James
Email: [email protected]
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada

\newline

*Coauthor #3*
Name: Patrick S. Curry
Email: [email protected]
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.

El answered 6/4, 2017 at 0:50 Comment(2)
This is perfect! I was able to get my desired output using a combination of \newline and adding double spaces at the end of lines. For those interested I posted the code that gave me the results I was seekingSouthard
This no longer works for me, however the answer below from @eric krantz worked (<br>) https://mcmap.net/q/526193/-add-blank-line-to-word-output-rmarkdownRosmunda
S
10

An answer was provided to me by chinsoon12. Here is the code I used to get the desired output. I do find it a little bit strange that I needed to write \newline \newline (rather than putting it only once). It was also not possible to add \newline at the end of a line of code and get the same effect. You need to have a line breaks in your .rmd file in order for it to work (at least from what I attempted).

---
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^ 

\newline

Affiliations: ^1^University of Michigan  

\newline  \newline

*Presenting author information*  
Name: John H. Curry  
Email: [email protected]  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

\newline \newline

*Coauthor #2*  
Name: Kathy S. James  
Email: [email protected]   
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

\newline \newline

*Coauthor #3*  
Name: Patrick S. Curry  
Email: [email protected]  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

\newline \newline

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

\newline \newline

## Methods
Here is where I write my methods

\newline \newline


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

\newline \newline

## Discussion
Here is where I write my discussion

\newline \newline
Southard answered 10/4, 2017 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.