Search code examples
rkableextra

How to not italicize the footnote title in kableExtra?


Footnote titles in kableExtra can be renamed but their standard format remains italic, as this is the default (see ?kableExtra::footnote()).


library(kableExtra)
library(dplyr)

mtcars %>%
 kbl() %>%
 kable_styling() %>%
 footnote(general = "Foo, bar", general_title = "Take note:", footnote_as_chunk = T)

How can I not italicise the new general_title using title_format?

I tried title_format = "normal" but this does not work.


Solution

  • For an HTML table, you can use the text_spec() function and make use of the extra_css argument. You need to set escape = FALSE in the footnote() function so the code is interpreted and not printed.

    library(kableExtra)
    
    mtcars |>
      head() |>
      kbl() |>
      kable_styling() |>
      footnote(
        general = "Foo, bar",
        general_title = text_spec("Take note:", extra_css = "font-style: normal;"),
        footnote_as_chunk = TRUE,
        escape = FALSE
      )
    

    enter image description here

    I think it would be worthwhile making a feature request to have 'normal' as a font style option as it seems a strange decision to force bold/italics/underline.