Closed EricMarcon closed 5 months ago
That happens when you use knitr::kable
without specifying the format, because kable
produces a markdown table, and kable_styling
can't recognize the existing label in it. Workarounds are to specify format = "html"
in the call to kable
, or use kableExtra::kbl()
instead. Then things are fine.
The reason kable_styling
has trouble here is that it's looking for a caption using the format that html_document
produces, but bookdown::html_document2
produces captions in a different format, since it includes table numbers.
Using kableExtra::kbl()
instead of knitr:kable()
works perfectly.
I suggest to write it in the documentation: always replace knitr:kable()
by kableExtra::kbl()
to avoid trouble with bookdown.
The other workaround, i.e. specify format = "html"
is not so good because markdown documents should be as independent as possible from the output format in my opinion.
Thanks for the solution.
I just dealt with this same double table in the captions of bookdown reports and was able to get around it by specifying param label = NA
within the knitr::kable()
function.
kable_styling()
makes "Table" appear twice in captions when knitted by bookdown to HTML with kableExtra v. 1.4.0. This was not the case with v. 1.3.This is a MWE of .Rmd file: