Search code examples
htmlrkableextra

The hold_position or Hold_position doesn't work in kableExtra?


I use kableExtra package to create some html format files.

And I use hold_position to change the caption location but it doesn't work.

The reproducible code below came from the kableExtra package official samples:

kbl(dt, caption = "Demo table", booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position"))

My result like this: enter image description here


Solution

  • Since your output is html, you could add <center>text<\center> to your caption:

    library(tidyverse)
    library(kableExtra)
    
    kbl(mtcars, caption = "<center>Demo table</center>", booktabs = T) %>%
      kable_styling(latex_options = "striped")
    

    -output

    enter image description here