2

I'm relatively new to knitr. I'm trying to create a document that includes a small table. For example, consider this rmd document:

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

When I knit this document the text "This text is after the table." gets formatted as if it is in the table.

I have found if I include an empty chunk between the kable(df) and the plain text that the plain text is formatted properly.

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

In this case, "Same table ..." is formatted correctly.

Are there parameters to kable that I should be using so that I can avoid inserting the empty chunk?

Thanks, Dave

oldNewbie
  • 23
  • 1
  • 5

1 Answers1

1

Add an extra line break (empty line) between the end of the chunk and your new paragraph:

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

Or use pander::pander, which does that automatically (by always adding an extra line-break after the table to avoid this confusion) with some further sugar:

---
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.
daroczig
  • 28,004
  • 7
  • 90
  • 124
  • Thank you. I swear I tried the extra blank line and it didn't work. However, when I just tried it again it worked great. – oldNewbie Jan 11 '16 at 13:29