如何保持kable格式化表格后面的文字?

时间:2016-01-08 14:43:25

标签: r-markdown

我对编织者来说比较新。我正在尝试创建一个包含小表的文档。例如,请考虑此rmd文档:

---
title: "Kable Test"
author: "Dave"
date: "January 8, 2016"
output: html_document
---

This R Markdown document is for testing kable output when kable is given a data.frame with only one row. 

```{r}
library(knitr)
df = data.frame(x=1,y=100,z=1000)

kable(df)
```
This text is after the table.

当我编写本文档时,文本"此文本在表格后面。"格式化就好像它在表格中一样。

我发现如果我在kable(df)和纯文本之间包含一个空块,那么纯文本格式正确。

```{r}
kable(df)
```
```{r}
```
Same table followed by an empty chunk.

在这种情况下,"同桌......"格式正确。

我应该使用kable的参数,以便我可以避免插入空块吗?

谢谢, 戴夫

1 个答案:

答案 0 :(得分:1)

在块的末尾和新段落之间添加额外的换行符(空行):

---
title: "Kable Test"
author: "Dave"
date: "January 8, 2016"
output: html_document
---

This R Markdown document is for testing kable output when kable is given a data.frame with only one row. 

```{r}
library(knitr)
df = data.frame(x=1,y=100,z=1000)

kable(df)
```

This text is after the table.

或者使用pander::pander,它会自动执行此操作(通过在表格之后添加额外的换行符以避免这种混淆)以及更多的糖:

---
title: "Kable Test"
author: "Dave"
date: "January 8, 2016"
output: html_document
---

This R Markdown document is for testing kable output when kable is given a data.frame with only one row. 

```{r}
library(knitr)
df = data.frame(x=1,y=100,z=1000)

pander::pander(df)
```
This text is after the table.