2017-04-05 65 views
2

美好的一天。將空行添加到Word輸出RMarkdown

我正在嘗試使用導出到word文檔的rmarkdown文件創建會議摘要提交。我試圖找到一種方法來在輸出的word文檔中插入一個空行。我發現可以通過在減價文件的末尾添加兩個空格來插入換行符,但是,當您只需要空白行時,此技巧不起作用。下面是示例代碼

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

當我編織文件時,可悲的是它有點聚集。下面我添加了一張帶有當前輸出的圖片(左圖)以及我希望它看起來像(右圖)的圖片。 Desired Output

我已閱讀論壇,並且在使用word文檔時我還沒有看到此解決方案。我將不勝感激任何建議。

謝謝

回答

5

你可以在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: [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 

如果你要問下,NEWPAGE是稍硬。您將需要爲標題5(例如)在單​​詞中創建新的樣式,該樣式將自動在新頁面上啓動,在您的Rmd文件中,您將使用標題5作爲新行。網上有很多關於這方面的資源。

+0

這是完美的!我能夠使用\ newline的組合和在行尾添加雙空格來獲得所需的輸出。對於那些有興趣的人,我發佈了代碼,它給了我正在尋找的結果 –

1

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