gtsummary is a great package for creating summary tables for HTML. I find myself needing to use LaTeX though, which is supported through gt::as_latex(). It seems to work, but it removes leading space from the rows.
For instance, if you have a factor, the gtsummary table will have a row per factor level with the level label indented so that it's easily distinguished from numerical variables. When you then convert the table to latex, it removes the leading spaces. Is there a way to stop it doing that?
library(gtsummary)
#> Warning: Paket 'gtsummary' wurde unter R Version 3.6.3 erstellt
library(gt)
#> Warning: Paket 'gt' wurde unter R Version 3.6.3 erstellt
data(mtcars)
mtcars$cyl <- factor(mtcars$cyl)
tab <- mtcars %>%
select(cyl) %>%
tbl_summary() %>%
as_gt()
tab
tab %>%
as_latex() %>%
as.character() %>%
cat()
#> \captionsetup[table]{labelformat=empty,skip=1pt}
#> \begin{longtable}{lc}
#> \toprule
#> \textbf{Characteristic} & \textbf{N = 32}\textsuperscript{1} \\
#> \midrule
#> cyl & \\
#> 4 & 11 (34\%) \\
#> 6 & 7 (22\%) \\
#> 8 & 14 (44\%) \\
#> \bottomrule
#> \end{longtable}
#> \vspace{-5mm}
#> \begin{minipage}{\linewidth}
#> \textsuperscript{1}Statistics presented: n (\%) \\
#> \end{minipage}
Created on 2020-11-06 by the reprex package (v0.3.0)