'Change the size of a title in KableExtra?

I have tried many techniques (mostly around editing the raw HTML passed to caption in order to change the size of a title (aka caption) when using KableExtra.

Minimal Reproducible Example

Here's a simple example:

library(knitr)
library(kableExtra)

iris %>%
  head %>%
  kable(
    table.attr = "style = \"color: black;\"", 
    caption = "<span style='font-size:20'>A lovely title</span>"
    ) %>%
  kable_styling("striped", full_width = T) 

But the title size doesn't change:

enter image description here



Solution 1:[1]

Span accepts CSS font-size in 3 different ways. Run the following examples to see them in action:

Pixels

library(knitr)
library(kableExtra)


iris %>% 
  head %>% 
  kable(
    table.attr = "style = \"color: black;\"", 
    caption = "<span style='font-size:20px'>A lovely title</span>"
    ) %>% 
  kable_styling("striped", full_width = T) 

Percent

iris %>% 
  head %>% 
  kable(
    table.attr = "style = \"color: black;\"", 
    caption = "<span style='font-size:200%'>A lovely title</span>"
    ) %>% 
  kable_styling("striped", full_width = T) 

"small", "large" etc.

iris %>% 
  head %>% 
  kable(
    table.attr = "style = \"color: black;\"", 
    caption = "<span style='font-size:small'>A lovely title</span>"
    ) %>% 
  kable_styling("striped", full_width = T) 

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1