ralignmentflextableheader-row

flextable: align ONLY header row to center


I have the following code which results in below fig. However I want the header_row to align center over the cols.(passed as arg.:colwidths, I've been searching, consulted the manual (but I'm new to R so my understanding is bad), but I'm at a lost. Everything else in the table should have the alignment it has.

ft <- flextable(df_BAS_sum)
ft <- set_caption(ft, caption =sprintf("Tabell 1. Arbetsmarknadsdata och nyckeltal för olika geografier, 20-64 år - %s %s", month, yr), align_with_table = F)
ft <- add_header_row(ft, colwidths = c(1,2,4,3), values = c("","Arbetskraften","Ej i arbetskraften","Nyckeltal"))
ft <- colformat_num(x = ft,
                    big.mark=" ", decimal.mark = ",",
                    na_str = "N/A")
ft <- theme_vanilla(ft)
ft

enter image description here

Thanks for any insight!


Solution

  • ft <- align(ft, i = 1, j = NULL, align = "center", part = "header")
    

    part = "header" restricts it to the header rows only i = 1 (first row) j = NULL (all columns) should avoid the undesirable realignment of the other header row.