As outlined in another post, the kableExtra
package has a function add_header_above()
which creates an additional header row in the output table on top of the actual column names. However, when setting fixed_thead = TRUE
in kable_styling()
to make the header sticky, the additional header row from the add_header_above()
call is not made sticky.
Minimal example to demonstrate the problem:
knitr::kable(mtcars) %>%
kableExtra::add_header_above(c(" " = 1, "Header 1" = 5, "Header 2" = 6)) %>%
kableExtra::kable_styling(fixed_thead = TRUE)
In the above linked previous post there is a solution given using shiny apps, but could someone please provide a solution for making the add_header_above()
headers sticky without using a shiny app? I'm looking for a solution that does not require knitting in r markdown, as I would like to be able to just save the table using save_kable()
instead of having to knit the whole script