3

I'm trying to print two table side-by-side through Rmarkdown, output as PDF.

I can print the tables out fine, but they end up stuck really close together and I cannot find a way to create more space between them. The solutions I find in other posts returns strange output or errors, e.g. the second one from here just gives an 'error 43': Align multiple tables side by side

My code is this:

```{r, echo=FALSE}
library(knitr)
kable(list(head(bymonth),head(bydecade)),align='c')
```

Tables

Anyone know how to add some spacing between those two tables?

Community
  • 1
  • 1
Gerard
  • 159
  • 1
  • 2
  • 11

1 Answers1

4

Incorporating the answer given here you could do it manually like this:

```{r, echo = FALSE, results = 'asis', warning = F}
library(knitr, quietly = T)
t1 <- kable(head(mtcars[,1:2]), format = 'latex')
t2 <- kable(head(mtcars[,3:4]), format = 'latex')
cat(c("\\begin{table}[h] \\centering ", 
      t1,
    "\\hspace{1cm} \\centering ",
      t2,
    "\\caption{My tables} \\end{table}"))  
```

The basic idea is to create the tables individually and align them with plain latex. The spacing is added by \\hspace{1cm}.

enter image description here

Community
  • 1
  • 1
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • Awsome, thanks, that works! However, for some reason whenever I use kable, it prints the tables at the bottom of the page, no matter how the code chunks and text is order in the Rmd file. Any advice on that perhaps? – Gerard Jan 30 '17 at 08:01
  • This is the standard LaTeX behavior. Check this link http://www.weinelt.de/latex/table.html . I change the answer by adding the option `[h]` to the table environment. I recommend reading a bit about LaTeX. – Martin Schmelzer Jan 30 '17 at 12:59
  • Ok cool, thanks. Yeah I've realised I'm going to have to get up to scratch with that as well on top of just the R coding! – Gerard Jan 31 '17 at 14:23