quartopdflatexkableextra

kable_styling overrides linesep = "" and adds space every 5 rows


This is partially related to this post, but for some reason I seem not to be able to fix my issue. In Quarto, when I create a table using kable with booktabs = TRUE and linesep = "" I get the expected results (no extra space every 5 rows):

---
title: "Test"
format: pdf
---

```{r}
library(kableExtra)
dat <- data.frame(v1 = letters[1:10], v2 = 1:10)
kable(dat, booktabs = TRUE, linesep = "")
```

No kable_styling, expected results.

If I use kable_styling() to get a striped table, an extra space is added after the fifth row:

---
title: "Test"
format: pdf
---

```{r}
library(kableExtra)
dat <- data.frame(v1 = letters[1:10], v2 = 1:10)
kable(dat, booktable = TRUE, linesep = "") |> 
  kable_styling(latex_options = "striped")
```

With kable_styling an extra space is added even with linesep = ""

I get the extra space when I use kable_styling() even without booktabs = TRUE:

---
title: "Test"
format: pdf
---

```{r}
library(kableExtra)
dat <- data.frame(v1 = letters[1:10], v2 = 1:10)
kable(dat) |> 
  kable_styling()
```

Extra space even without booktabs = TRUE

To my understanding this is not the expected behavior of kable_styling(), is there something I am missing?


Solution

  • You are not missing something, the .tex processing seems to work different here. However, you could include a \setlength{\defaultaddspace}{0pt} in the header, this also makes the spaces go away.

    ---
    title: "Test"
    format: 
      pdf:
        include-in-header:
          text: |
            \setlength{\defaultaddspace}{0pt}
    ---
    
    ```{r}
    library(kableExtra)
    dat <- data.frame(v1 = letters[1:10], v2 = 1:10)
    kable(dat) |> 
      kable_styling()
    ```
    

    enter image description here