0

I'm trying to put multiple tables on a single line in a R Markdown document. I'm able to do that by kable %>% kableStyling(... ,position='float_left') and the tables line up nicely across a page:

enter image description here

However, when resuming text after these tables (headings, text, anything, really), it starts to the right of the last table on the line. Here is a simple example:

---
output:
  html_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = TRUE)
  require(kableExtra)
``` and
```{r Test, echo=F}
  d1 <- data.frame(Item=c('A','B','C'),Value = c(1,2,3),Units=c('X','Y','Z'))
  knitr::kable(d1,format='html') %>%
    kable_styling(position='float_left',full_width=F)
```

## Next heading

enter image description here

I would have expected that ## Next heading would start on a new line. This happens both with format='html' and format='latex':

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
Dr Dave
  • 453
  • 1
  • 4
  • 11

1 Answers1

2

As stated by the kableExtra documentation about the float options:

You can also wrap text around the table using the float-left or float-right options.

So the behaviour you are witnessing is as would be expected for the package.

An easy workaround for your situation is to make the last table on each line use the argument position='left' instead of position='float_left'

---
output: html_document
---

```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = TRUE)
  require(kableExtra)
```

```{r Test, echo=F}
  d1 <- data.frame(Item=c('A','B','C'),Value = c(1,2,3),Units=c('X','Y','Z'))
  knitr::kable(d1,format='html', caption = "Table 1") %>%
    kable_styling(position='float_left',full_width=F)


    knitr::kable(d1,format='html', caption = "Table 2") %>%
    kable_styling(position='float_left',full_width=F)

      knitr::kable(d1,format='html', caption = "Table 3") %>%
    kable_styling(position='left',full_width=F)

```    
# Next heading

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84