The answer depends somewhat on whether you are using R markdown to create entire LaTeX documents, or whether you're grabbing the LaTeX code for a single table and adding it manually to a larger document.
R Markdown: {gtsummary} supports output to PDF/LaTeX via a few different engines--gt (although, technically still under development for LaTeX. for simple tables I have had no problems with gt and Latex working nicely together), flextable, huxtable, kable, and kableExtra. http://www.danieldsjoberg.com/gtsummary/dev/articles/rmarkdown.html Using one of these output options for the gtsummary table should work for you.
If you need to convert a single gtsummary table to LaTeX or HTML, you will first want to convert is to {gt} then use the functions gt::as_latex()
or gt::as_raw_html()
. These will aid in getting the raw HTML or Latex code you're after.
library(gtsummary)
library(tidyverse)
trial %>%
select(age, trt) %>%
tbl_summary() %>%
as_gt() %>%
gt::as_latex()
\captionsetup[table]{labelformat=empty,skip=1pt}
\begin{longtable}{lc}
\toprule
\textbf{Characteristic} & \textbf{N = 200}\textsuperscript{1} \\
\midrule
Age, yrs & 47 (38, 57) \\
Unknown & 11 \\
Chemotherapy Treatment & \\
Drug A & 98 (49\%) \\
Drug B & 102 (51\%) \\
\bottomrule
\end{longtable}
\vspace{-5mm}
\begin{minipage}{\linewidth}
\textsuperscript{1}Statistics presented: median (IQR); n (\%) \\
\end{minipage}
I hope this is close to what you need/are looking for! Happy Coding!