I have been using a script from a year ago, where the tables rendered in the correct places but am wondering if anything has changed with the rendering to pdf command? Just as an example, if I use:
Table %>%
tbl_summary(by = Schools,
statistic = all_categorical() ~ "{p}%",
missing_text = "(Missing Data)") %>%
bold_labels() %>%
modify_footnote(c(all_stat_cols()) ~ NA) %>%
modify_table_body(filter,
!(variable == "SEN" & label == "Place +")) %>%
modify_table_body(filter,
!(variable == "SEN" & label == "Watchlist"))
the table is not produced where it should be. I notice that if I use kable then it reproduces in the correct location (i.e., where it is placed on the quarto document). I'd prefer not to have to change all the tables as there will be hundreds of them, so I was wondering if anyone knows if there is some additional command I should be using nowadays to ensure the table is generated in the location where it presented in the quarto document? Any help would be welcomed
I had the same issue using LaTeX for my thesis. The gist is, that your tables and figures need to be positioned using \begin{table/figure}[H]. There is a package for this called float that allows you to set this position automatically using \floatplacement{table}{H} in your preamble. In quarto you can include packages in the header directly in the YAML.
---
title: "Mtcar example"
format:
pdf:
latex-auto-install: true
include-in-header:
- text: |
\usepackage{float}
\floatplacement{table}{H}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
pacman::p_load(gtsummary)
```
## Tables
```{r table}
tbl_summary(mtcars[,c("mpg", "disp", "hp")])
```
```{r table2}
tbl_summary(mtcars[,c("mpg", "disp")])
```
This places the tables exactly where they are defined in your LaTeX document: