Side by side kables return "Not in outer par mode"

Viewed 318

This is presumably related to latex kable side-by-side tables "Not in outer par mode" but the solution identified by the author, to use latex_options = c("Hold_position") is not changing the outcome for me when I try to knit to PDF. The author's full comment reads:

I got the tables to display side-by-side by adding kable_styling(latex_options = c("striped", "Hold_position")).

Here is a minimal example that works fine:

---
title: "Example Document"
date: "Last compiled on `r format(Sys.time(), '%d %B, %Y at %H:%M ')`"
output: pdf_document
---

```{r setup, include=FALSE, echo=FALSE}
library(tidyverse)
library(kableExtra)
```

``` {r species}  
kable(caption = "Species",
      starwars %>%
        count(species) %>%
        filter(n > 1)
) %>% kable_styling(latex_options = c("striped", "Hold_position"))    
```

``` {r planet} 
 kable(caption = "Homeworld",
      starwars %>%
        count(homeworld) %>%
        filter(n > 1)
    )%>% kable_styling(latex_options = c("striped", "Hold_position"))
```

When I use knitr::kables to combine them into a pair of side-by-side tables, I can run the code chunk and knit to HTML just fine, but I'm still getting a "not in outer par mode" error:

! LaTeX Error: Not in outer par mode.

Error: LaTeX failed to compile 10_knit_doesnt.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 10_knit_doesnt.log for more info.
Execution halted

The actual code chunk is this:

``` {r side by side} 

knitr::kables(list(
  kable(caption = "Species",
    starwars %>%
      count(species) %>%
      filter(n > 1)
    ) %>% kable_styling(),
    kable(caption = "Homeworld",
      starwars %>%
        count(homeworld) %>%
        filter(n > 1)
    ) %>% kable_styling()
    
  )
) %>% kable_styling(latex_options = c("striped", "Hold_position"))
```

I've tried moving the styling (kable_styling(latex_options = c("striped", "Hold_position")) ) into the individual tables, but that doesn't seem to have any impact.

knitr::kables(list(
  kable(caption = "Species",
    starwars %>%
      count(species) %>%
      filter(n > 1)
    ) %>% kable_styling(latex_options = c("striped", "Hold_position")),
    kable(caption = "Homeworld",
      starwars %>%
        count(homeworld) %>%
        filter(n > 1)
    ) %>% kable_styling(latex_options = c("striped", "Hold_position"))
    
  )
) %>% kable_styling()

Can I knit to PDF while using side-by-side tables?

0 Answers
Related