Output tables in word can be a little messy, because the default table format prints poorly to .docx formats.
starwars |>select(1:7) |>slice(1:10)
# A tibble: 10 × 7
name height mass hair_color skin_color eye_color birth_year
<chr> <int> <dbl> <chr> <chr> <chr> <dbl>
1 Luke Skywalker 172 77 blond fair blue 19
2 C-3PO 167 75 <NA> gold yellow 112
3 R2-D2 96 32 <NA> white, bl… red 33
4 Darth Vader 202 136 none white yellow 41.9
5 Leia Organa 150 49 brown light brown 19
6 Owen Lars 178 120 brown, grey light blue 52
7 Beru Whitesun Lars 165 75 brown light blue 47
8 R5-D4 97 32 <NA> white, red red NA
9 Biggs Darklighter 183 84 black light brown 24
10 Obi-Wan Kenobi 182 77 auburn, white fair blue-gray 57
Flex tables is a neat tool to get around this but requires a bit of setting up for specific formatting. A work around for this can be defining your own flextable themes for different formats and calling it depending on the table.
It is worthwhile to start with a base theme, which is applied to all tables.
flex_theme_base <-function(ft) { nr <-nrow_part(ft, part ="body") ft |>font(fontname ="Arial (Body)", part ="all") |>fontsize(size =10, part ="all") |>align(align ="left", part ="all") |>valign(valign ="middle", part ="all") |>bold(part ="header") |>bold(i =seq_len(nr), j =1, part ="body") |>bg(i =1, bg ="#F0F0F0", part ="header") |>border_remove() |>border(border = officer::fp_border(color ="#CCCCCC"), part ="all") |>autofit()}