The tab_spanner_delim() function

Use iris to create a gt table and use the tab_spanner_delim() function to automatically generate column spanner labels. This splits any columns that are dot-separated between column spanner labels (first part) and column labels (second part).

iris |>
  dplyr::group_by(Species) |>
  dplyr::slice(1:4) |>
  gt() |>
  tab_spanner_delim(delim = ".")
Sepal Petal
Length Width Length Width
setosa
5.1 3.5 1.4 0.2
4.9 3.0 1.4 0.2
4.7 3.2 1.3 0.2
4.6 3.1 1.5 0.2
versicolor
7.0 3.2 4.7 1.4
6.4 3.2 4.5 1.5
6.9 3.1 4.9 1.5
5.5 2.3 4.0 1.3
virginica
6.3 3.3 6.0 2.5
5.8 2.7 5.1 1.9
7.1 3.0 5.9 2.1
6.3 2.9 5.6 1.8