Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format captions in kableExtra()

Is it possible to format captions in kableExtra? I would like to center and bold a caption for a table when knitting to HTML in RMarkdown. I have tried to wrap the table in a CSS div where the text was centered, but this did not produce the intended result.

Sample table:

library(kableExtra)
kable(data.frame(a = 1:3, b = 4:6), caption = "CENTER") %>%
  kable_styling(bootstrap_options = "striped")

Yields:

enter image description here

I would like:

enter image description here

like image 849
Bjørn Kallerud Avatar asked Jun 23 '26 15:06

Bjørn Kallerud


1 Answers

If the final format is HTML:

write caption within HTML center and strong tag and set escape to FALSE.

kable(
    data.frame(a = 1:3, b = 4:6), 
    caption = "<center><strong>CENTER</strong></center>",
    escape = FALSE,
    format = "html"
) %>%
    kable_styling(bootstrap_options = "striped")
like image 113
yusuzech Avatar answered Jun 25 '26 09:06

yusuzech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!