jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

Column label size change in gt_theme_dark #77

Closed debruine closed 1 year ago

debruine commented 1 year ago

Description

It is very hard to change the column label size when using gt_theme_dark(). It is stuck at 12px without the awkward workaround I found (below). I haven't checked if this is a problem for other themes.

Reproducible example

library(gt)

# changes column label size 
head(mtcars) |> gt() |> 
  tab_options(column_labels.font.size= 30)

# does not change column label size
head(mtcars) |> gt() |> 
  gtExtras::gt_theme_dark(column_labels.font.size= 30)

# nor does this
head(mtcars) |> gt() |> 
  gtExtras:: gt_theme_dark() |>
  tab_options(column_labels.font.size= 30)

# this works
head(mtcars) |> gt() |> 
  gtExtras:: gt_theme_dark() |>
  tab_style(style = cell_text(size = px(30)),
            locations = cells_column_labels(everything()))

Expected result

The first two examples with gt_theme_dark should have increased the size of the column labels, but did not.

Session info

R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.6

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] gt_0.7.0

loaded via a namespace (and not attached): [1] pillar_1.8.1 compiler_4.2.1 gtExtras_0.4.2 tools_4.2.1
[5] digest_0.6.29 lifecycle_1.0.2 tibble_3.1.8 gtable_0.3.1
[9] pkgconfig_2.0.3 rlang_1.0.6 cli_3.4.1 DBI_1.1.3
[13] rstudioapi_0.14 xfun_0.33 fastmap_1.1.0 dplyr_1.0.10
[17] knitr_1.40 paletteer_1.4.1 generics_0.1.3 vctrs_0.4.2
[21] sass_0.4.2 grid_4.2.1 tidyselect_1.1.2 fontawesome_0.3.0 [25] glue_1.6.2 R6_2.5.1 fansi_1.0.3 ggdark_0.2.1
[29] rematch2_2.1.2 purrr_0.3.4 ggplot2_3.3.6 magrittr_2.0.3
[33] scales_1.2.1 htmltools_0.5.3 ellipsis_0.3.2 assertthat_0.2.1 [37] colorspace_2.0-3 faux_1.1.0 utf8_1.2.2 munsell_0.5.0

jthomasmock commented 1 year ago

Hi @debruine - thanks for the reprex!

I'm finding out that users are not expecting the difference between:

tab_options(column_labels.font.size)
# and
tab_style()

Now that more is possible via tab_options(), I'll move as much as possible into there. Generally, tab_style() is greater precedence in the CSS, so that's why it works.

Should have a fix for this this week.

jthomasmock commented 1 year ago
library(gt)
library(gtExtras)

packageVersion("gtExtras")
#> [1] '0.4.5'

# does not change column label size
head(mtcars) |> gt() |> 
  gt_theme_dark(column_labels.font.size= 30) |> 
  gtsave("test2.png")

knitr::include_graphics("test2.png")

Created on 2022-11-21 by the reprex package (v2.0.1)