2

Context: I am knitting an Rmarkdown report mixing landscape and portrait layouts. I use the technique described here: https://stackoverflow.com/a/41945462/10264278.

Problem: there is an unexpected table layout problem. when the table is made using kableExtra::kable() it does not follow the expected orientationif a caption is filled in kable(caption =...).

Reproducible example:

---
output: pdf_document
header-includes:
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---

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

library(dplyr)
library(kableExtra)
```

\blandscape
```{r}
mtcars # displays properly

mtcars %>% kable(caption = "test", digits = 2) # the table follows the landscape layout and does not remains "still"/"horizontal"
```
\elandscape

The output:

Table on the left (mtcars) is displayed as expected. But, if I use kable() the table "turns with the page" witch is not expected.

enter image description here

EDIT:

I am aware that kableExtra::landscape() exists. But this function creates a new page for each table. Here I have many few-rows tables that are very wide. Thus I do not want to have a single table per page.

Example:

```{r}
head(mtcars, 5) %>% kable(caption = "test", digits = 2) %>% landscape(margin = NULL)
head(mtcars, 5) %>% kable(caption = "test", digits = 2) %>% landscape(margin = NULL)

```

Output: enter code here

EDIT 2:

This problem occurs only if a caption is specified in kable(caption = ...).

Example:

\blandscape
```{r}
mtcars # displays properly

mtcars %>% kable(digits = 2) # the table follows the landscape layout and does not remains "still"/"horizontal"
```
\elandscape

Output: enter image description here

Paul
  • 2,850
  • 1
  • 12
  • 37
  • did you find a way to do this? I'm having the same issue. – Severe_Dragomere Apr 24 '22 at 01:18
  • @Severe_Dragomere unfortunately no, I had to gave up. I went back to use MS Word with package [flextable](https://davidgohel.github.io/flextable/index.html#flextable-r-package) that has amazing export capabilities and custom options. – Paul Apr 25 '22 at 08:01

0 Answers0