I have a table generated with kableExtra with a footnote that spans over several columns. If I run it separately in R it displays properly. However, when run inside a Quarto document, it constraints the text of the footnote to the width of the 1st column.
Here is a reproducible example
library(kableExtra)
dt <- mtcars[1:5, 1:4]
# HTML table
kbl(dt, caption = "Demo Table") %>%
kable_styling(bootstrap_options = "striped",
full_width = F) %>%
add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
footnote(c("Let's make a very long table footnote"))
Has any one experienced this before, and if so knows how to fix it?
When knitting Quarto to PDF (via LaTeX) adding
threeparttable = TRUE
argument tofootnote()
works:This is using the threeparttable LaTeX package to produce the effect that we want. This option is explicitly mentioned here.
With HTML, I'm afraid this problem is much more difficult because you wont have access to LaTeX packages so
threeparttable = TRUE
won't work. Plyaing around with your code - I noticed that removing your header row actually allowed the text to extend more. So removing this code produced that effect:Based on that, the footnote wrapping is somehow due to the formatting of the header column of the groups. I played with arguments of the many functions and was unable to find a definitive way to prevent the text wrapping. It seems like some folks have had some issues with the new(er) Quarto format and this package, maybe worth reading some of the open issues here.
In light of all of this, I'd recommend either switching to PDF format, forgoing the header row, or looking into other packages that may be able to accomplish this (
gt
maybe?).