Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: [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

like image 323
Patrick Avatar asked Apr 05 '17 19:04

Patrick


3 Answers

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

like image 87
Eric Krantz Avatar answered Oct 26 '22 22:10

Eric Krantz


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.

like image 21
chinsoon12 Avatar answered Oct 26 '22 22:10

chinsoon12


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
like image 35
Patrick Avatar answered Oct 26 '22 21:10

Patrick