kableExtra rmarkdown tables - aligning grouping row labels and footnotes

Viewed 1906

I am using kableExtra to format some tables in an Rmarkdown document. When running the code below, without any position argument to kable_styling, the grouping row labels (the rows in the table where it says "Group 1" and "Group 2") and the footnotes remain left aligned in relation to the table. This is as I would like it.

```{r cars-table, results='asis'}
kable(mtcars[1:10, 1:2], format = "html", caption = "Group Rows", 
     col.names = c("MPG[note]", "CYL[note]")) %>%
kable_styling("striped", full_width = F) %>%
group_rows("Group 1", 4, 7) %>%
group_rows("Group 2", 8, 10) %>% 
add_footnote(c("Some footnote", "Some other footnote"))
```

kableExtra_workingtable

But when a position argument is provided to kable_styling, the grouping row labels and footnotes seem to take the opposite alignment, rather than remaining left aligned in relation to the table. I say the opposite alignment, as when I use position = "right", the grouping row labels and footnotes become left aligned.

The code below demonstrates the issue when using position = "left".

```{r cars-table, results='asis'}
kable(mtcars[1:10, 1:2], format = "html", caption = "Group Rows", 
     col.names = c("MPG[note]", "CYL[note]")) %>%
kable_styling("striped", full_width = F, position = "left") %>%
group_rows("Group 1", 4, 7) %>%
group_rows("Group 2", 8, 10) %>% 
add_footnote(c("Some footnote", "Some other footnote"))
```

kableExtra_notworkingtable

I only load two libraries to make this example and use the defaults when opening an .Rmd document in RStudio.

library(knitr)
library(kableExtra)

What can I do to make the grouping row labels and footnotes left aligned in relation to the table? Thanks.

1 Answers
Related