This is a follow up question to this.
Background: I’m trying to mimic the table format used in the DCR journal.
In my gt table I only want 3 lines as shown here (my desired output):
To achieve this I use gt::opt_table_lines(extent = "none")
to remove all lines, and add the 3 lines manually.
Here is my code (note there is no line under Primary Localisation
):
library(gt)
library(gtsummary)
tbl_trial <- trial |>
tbl_summary(by = trt, includ = c(age, grade)) |>
add_p(pvalue_fun = label_style_pvalue(digits = 2)) |>
add_overall() |>
add_n() |>
modify_header(label ~ "**Variable**") |>
modify_spanning_header(c("stat_1", "stat_2") ~ "**Treatment Received**") |>
modify_footnote_header("Median (IQR) or Frequency (%)", columns = all_stat_cols()) |>
bold_labels() |>
modify_spanning_header(all_stat_cols() ~ "**Primary Localisation**") |>
as_gt() |>
# Removes all lines
gt::opt_table_lines(extent = "none")
tbl_trial |>
gt::tab_header(
title = gt::md("TABLE 2. Tumor characteristics")
) |>
gt::tab_style(
style = gt::cell_text(align = "left", weight = "bold", color = "white"),
locations = gt::cells_title(groups = "title")
) |>
gt::tab_style(
style = gt::cell_fill(color = "#0066b3"),
locations = gt::cells_title(groups = "title")
) |>
# Line 1
# Thin blue line under spanning header ("Primary Localisation")
tab_options(column_labels.border.bottom.color = "#0066b3") |>
gt::tab_style(
style = cell_borders(
sides = "bottom",
color = "#0066b3",
weight = px(1)
),
locations = gt::cells_column_spanners()
) |>
# Line 2
# Bold blue line under column labels ("Characteristics")
gt::tab_style(
style = gt::cell_borders(
sides = "bottom",
color = "#0066b3",
weight = px(3)
),
locations = gt::cells_column_labels()
) |>
# Line 3
# Bold blue line at the bottom of the table
tab_style(
style = cell_borders(
sides = "bottom",
color = "#0066b3",
weight = px(3)
),
locations = gt::cells_body(rows = nrow(tbl_trial[["_data"]]))
)
My question:
How can I add the line under Primary Localisation
manually?
Simply add
|> opt_css(css = "
.gt_column_spanner {
border-bottom-style: solid !important;
border-bottom-width: 3px !important;
}")
as per my previous answer