Rich Majerus
Rich Majerus

Reputation: 41

More than three xtables on a page in knitr

I am trying to place more than three tables on one page of a pdf using knitr and xtable. The following code places the fourth table on the second page. If they are size appropriate, is there a way to include all of the tables on one page?

The following example places the fourth table on the second page, although there appears to be room on the first page.

---
title: "Example Code"
---

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

options(xtable.comment = FALSE)

library(xtable)    
```

```{r t1, results='asis'}
xtable(cars[1:2,])
```

```{r t2, results='asis'}
xtable(cars[3:4,])
```

```{r t3, results='asis'}
xtable(cars[5:6,])
```

```{r t4, results='asis'}
xtable(cars[7:8,])
```

Upvotes: 2

Views: 107

Answers (1)

CL.
CL.

Reputation: 14957

I think this is due to one of the settings like totalnumber or \textfraction explained here on TEX.SE. However, I couldn't come up with settings that place all four tables on one page so far.

Therefore, if the tables don't need to actually float, I suggest loading the float package and using the position specifier H:

---
title: "Example Code"
output: pdf_document
header-includes:
  - \usepackage{float}
---


```{r setup, include=FALSE}
options(xtable.table.placement  = "H")
library(xtable)
```

```{r t1, results='asis'}
xtable(cars[1:2,])
```

```{r t2, results='asis'}
xtable(cars[3:4,])
```

```{r t3, results='asis'}
xtable(cars[5:6,])
```

```{r t4, results='asis'}
xtable(cars[7:8,])
```

Output

Upvotes: 1

Related Questions