Search code examples
rlatexknitrr-markdown

Align multiple tables side by side


The following code produces 2 tables on top of each other. How would I set it to have them aligned side by side, e.g. 3 to a row?

---
title: "sample"
output: pdf_document
---

```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```   

```{r sample, echo=FALSE, results='asis'}
library(knitr)
t1 <- head(mtcars)[1:3]
t2 <- head(mtcars)[4:6]
print(kable(t1))
print(kable(t2))
```

Output looks like this: enter image description here


Solution

  • Just put two data frames in a list, e.g.

    t1 <- head(mtcars)[1:3]
    t2 <- head(mtcars)[4:6]
    knitr::kable(list(t1, t2))
    

    Note this requires knitr >= 1.13.