将空行添加到Word输出RMarkdown

时间:2017-04-05 19:20:18

标签: ms-word rstudio knitr r-markdown blank-line

美好的一天。

我正在尝试使用导出到word文档的rmarkdown文件创建会议摘要提交。我试图找到一种方法在输出的word文档中插入一个空行。我发现可以通过在markdown文件的末尾添加两个空格来插入换行符,但是,当你只想要一个空行时,这个技巧不起作用。以下是示例代码

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

当我编织文件时,可悲的是它有点聚集。下面我添加了一张带有当前输出的图片(左)和我希望它看起来像(右)。 img

我已经阅读了论坛,在使用word文档时我还没有看到解决方案。我很感激任何建议。

谢谢

3 个答案:

答案 0 :(得分:16)

您可以在Rmd文件中使用\newline,如下所示:

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

如果您要问下一个,新页面会稍微困难一些。您需要为标题5(例如)创建一个新的样式,在新页面上自动启动,在您的Rmd文件中,您将使用标题5作为新行。尽管如此,网上有很多资源。

答案 1 :(得分:7)

chinsoon12为我提供了答案。这是我用来获得所需输出的代码。我觉得有点奇怪,我需要写\ newline \ newline(而不是只放一次)。也不可能在一行代码的末尾添加\ newline并获得相同的效果。您需要在.rmd文件中包含换行符才能使其正常工作(至少从我尝试过的开始)。

---
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: curry@umed.edu  
Affiliation details: Kinesiology, University of Somewhere, Ottawa, Canada  

\newline \newline

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

\newline \newline

*Coauthor #3*  
Name: Patrick S. Curry  
Email: curry2@umed.edu  
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

答案 2 :(得分:6)

2年前,我对答案进行了投票,但现在\ newline对我不起作用。但是,
有效。确保
上方和下方有空白空间。也适用于图表和代码片段输出。

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

结果如下: Results