Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double "Table" in caption #831

Closed
EricMarcon opened this issue Mar 29, 2024 · 4 comments
Closed

Double "Table" in caption #831

EricMarcon opened this issue Mar 29, 2024 · 4 comments

Comments

@EricMarcon
Copy link

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:

---
title: "Double Table"
output:
  bookdown::html_document2
---

```{r}
cars |>
  knitr::kable(caption = "Cars data") |>
  kableExtra::kable_styling()
```

The caption obtained in the HTML output is "Table 1: Table 2: Cars data". This does not happen when the output format is bookdown::pdf_document2.
Removing kable_styling() from the pipeline solves the issue.

Thanks for your great package.

@dmurdoch
Copy link
Collaborator

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.

@dmurdoch
Copy link
Collaborator

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.

@EricMarcon
Copy link
Author

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.

@NewGraphEnvironment
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants