% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/merge_tables.R
\name{merge_tables}
\alias{merge_tables}
\title{Merge gtregression tables and preserve structure and notes}
\usage{
merge_tables(
  ...,
  spanners = NULL,
  theme = "minimal",
  format = c("flextable", "gt")
)
}
\arguments{
\item{...}{Two or more \code{gtregression} objects containing
\code{$table_display}.}

\item{spanners}{Character vector of spanner labels, one per table.
If \code{NULL}, defaults to \code{"Table 1"}, \code{"Table 2"}, etc.}

\item{theme}{Merge theme preset or vector of primitives.}

\item{format}{Output table format. One of \code{"flextable"} (default) or
\code{"gt"}. The merged display is rebuilt in this format, independently
of the formats used by the input tables.}
}
\value{
A merged table object of class
  \code{c("gtregression", "merged_table", ...)}.
}
\description{
Merge gtregression tables and preserve structure and notes
}
\details{
Binary variables should use the same row display across all input tables.
For a descriptive, univariable, and multivariable merge, the clearest
publication layout is usually \code{show_dichotomous = "all_levels"} in
\code{descriptive_table()} and \code{show_ref = TRUE} in each regression
function. Mixing these settings can create additional binary rows; in that
situation \code{merge_tables()} issues a warning with the compatible
settings.

Footnotes created by each input table are retained unchanged. Exact duplicate
notes are shown once in the merged table.
}
\examples{
birthwt_data <- data_birthwt |>
  dplyr::mutate(
    race = factor(race, levels = c(1, 2, 3),
                  labels = c("White", "Black", "Other")),
    smoke = factor(smoke, levels = c(0, 1), labels = c("No", "Yes")),
    ht = factor(ht, levels = c(0, 1), labels = c("No", "Yes")),
    low = factor(low, levels = c(0, 1), labels = c("Normal BW", "Low BW"))
  )

uni_tbl <- uni_reg(
  data = birthwt_data,
  outcome = "low",
  exposures = c("age", "lwt", "smoke", "ht"),
  approach = "logit"
)

multi_tbl <- multi_reg(
  data = birthwt_data,
  outcome = "low",
  exposures = c("smoke", "ht"),
  adjust_for = c("age", "lwt"),
  approach = "logit"
)

merge_tables(
  uni_tbl,
  multi_tbl,
  spanners = c("Univariable", "Adjusted")
)
}
