The following piece of code produces a table with the header of the first column centered. It should be left aligned. I have not found a way of changing the alignment for just this header. Can it be done?
The culprit seems to be tab_spanner
. If that is omitted, alignment works.
library(tidyverse)
my_df <- structure(list(Bundesland = c("Burgenland", "Kärnten", "Niederösterreich"
), `Positiv M` = c(4065, 4814, 4114), `Positiv W` = c(4013, 5222,
4128), `Verstorben M` = c(82, 131, 76), `Verstorben W` = c(70,
115, 69)), row.names = c(NA, -3L), class = c("tbl_df", "tbl",
"data.frame"))
my_df %>%
gt() %>%
fmt_number(columns=2:5,decimals = 0,
sep_mark = ".",dec_mark = ",") %>%
tab_spanner("pro 100.000",2:5)
This is a recent bug that was patched, and you can use the following after installing the dev version: https://github.com/rstudio/gt/issues/607
library(devtools)
devtools::install_github('rstudio/gt')
my_df %>%
gt() %>%
fmt_number(columns=2:5,decimals = 0,
sep_mark = ".",dec_mark = ",") %>%
cols_align(columns = 1,
align = "left") %>%
tab_spanner("pro 100.000",2:5)
Assuming this is your expected result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.