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

table caption adds [H] when i use HOLD_position option in kable_styling in pdf output #839

Open
bhattmaulik opened this issue Apr 21, 2024 · 4 comments

Comments

@bhattmaulik
Copy link

bhattmaulik commented Apr 21, 2024

I am using Quarto to prepare a document. I want to render it as PDF/Latex document. In this document, I need some tables, which I am formatting using kableExtra package. I want to HOLD the position of the table, so that they don't appear on the next page. But when I add "HOLD_position" option in the kable_styling, it adds an extra [H] above the table. Let me share a minimal example of this.


title: "Table Position"
format: pdf
editor: visual

Quarto

Load the packages required

library(tidyverse) #optional
library(knitr)
library(kableExtra)

Experiment with the data

#| echo: false 
#| label: tbl-cars 
#| tbl-cap: "Some cars" 
head(mtcars) |> kableExtra::kbl(booktabs = TRUE) |> kable_styling(latex_options = c("striped", "bordered","HOLD_position"),full_width = FALSE) %>%   column_spec(2, width = "30em")

If I use the option tbl-cap-location: bottom, then the table caption comes at the bottom of the table, but this [H] still remains at the top of the table. When I remove the "HOLD_position" option, this [H] goes away. When I use "hold_position" instead of "HOLD_position", it adds [!h] above the table instead of [H]. How can I get rid of these extra additions to the table?

@bhattmaulik
Copy link
Author

I just solved it by removing the "HOLD_position" argument, and putting the following code in the preamble:

\AtBeginDocument{
\floatplacement{table}{H}
}

@mine-cetinkaya-rundel
Copy link

I'm running into this too with kableExtra 1.4.0.4.

@dmurdoch
Copy link
Collaborator

dmurdoch commented Apr 29, 2024

I don't see this in the equivalent R Markdown document, so it's likely some small difference in the way LaTeX is generated between the two systems. I don't use Quarto, so someone else will have to come up with a PR.

@cderv
Copy link

cderv commented Apr 29, 2024

I confirm this is a Quarto issue for when the table is cross reference (meaning label has a tbl-prefix)

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

4 participants