Use the exibble dataset to create a gt table. We’ll add a spanner column label over three columns (date, time, and datetime) with tab_spanner(). The spanner column label can be styled with tab_style() by using the cells_column_spanners() function in locations. In this example, we are making the text of the column spanner label appear as bold.
Use the exibble dataset to create a gt table. We’ll add two spanners for the column combinations of (num, char) and time related columns (time and datetime). Furthermore we add another level of spanners with a column label over all date- and time related columns (date, time, and datetime). We want all spanner labels with “time” in their name to be bold. Additionally we want the text to be red of the spanner that is both time- related and on level 1.
exibble |> dplyr::select(-fctr, -currency, -group) |>gt(rowname_col ="row") |>tab_spanner(label ="time related cols",columns =c(datetime, time) ) |>tab_spanner(label ="num and char",columns =c(num, char) ) |>tab_spanner(label ="date and time cols",columns =c(date, time, datetime) ) |>tab_style(style =cell_text(weight ="bold"),locations =cells_column_spanners(spanners = tidyselect::contains("time")) ) |>tab_style(style =cell_text(color ="red"),locations =cells_column_spanners(spanners = tidyselect::contains("time"),levels =1 ) )