Closest thing I can give to what you want is with the below code by removing the top border in cases where the grouped variable is set to an empty character. What is left is to find a way to align each group to the center of each respective area but maybe you're ok with just that.
library(dplyr)
library(gt)
is_empty <- function(x){
return(ifelse(x == "", TRUE, FALSE))
}
tibble(colA = c("A", "A", "B", "B", "C", "C"),
colB = c("1", "23", "245", "123", "134", "98"),
colC = c("342", "34", "45", "23", "13", "982")) |>
group_by(colA) |>
mutate(colA = ifelse(row_number() == 1, colA, "")) |>
ungroup() |>
gt() |>
tab_style(
style = list(
cell_borders(
sides = c("top", "bottom"),
weight = px(0)
)),
locations = list(
cells_body(
columns = colA,
rows = is_empty(colA)
)
)
)
