Ranji Raj
Ranji Raj

Reputation: 818

Extra white space after knitting in Rmarkdown

I am trying to generate a table using kableExtra on the toy iris data. I am able to successfully generate my output in PDF but I get some white spaces after the 5th row.

set.seed(123)
library(dplyr)
library(kableExtra)
df<- slice_sample(iris, n = 10)

kbl(df, caption = "Iris dataset", booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position"))

I couldn't find any trim flags or so that I can pass them to the slice_sample. Not sure why it persists or is it by design?

kableExtra

Upvotes: 1

Views: 853

Answers (1)

Peter
Peter

Reputation: 12739

The line spacing is a result of selecting booktabs = TRUE in the call to kbl which by definition includes '\addlinespace' in the default linesep argument every fifth row to make it easier to scan tables.

You can override this by setting linesep = "". Or for that matter introduce spacing in any order you like.

kbl(df, caption = "Iris dataset", booktabs = TRUE, linesep = "" ) %>%
kable_styling(latex_options = c("striped", "hold_position"))

enter image description here

Upvotes: 2

Related Questions