Apply theme APA (the stylistic style of the American Psychological Association) to a flextable

theme_apa(x, ...)

Arguments

x

a flextable object

...

unused

Illustrations

behavior

Theme functions are not like 'ggplot2' themes. They are applied to the existing table immediately. If you add a row in the footer, the new row is not formatted with the theme. The theme function applies the theme only to existing elements when the function is called.

That is why theme functions should be applied after all elements of the table have been added (mainly additionnal header or footer rows).

If you want to automatically apply a theme function to each flextable, you can use the theme_fun argument of set_flextable_defaults(); be aware that this theme function is applied as the last instruction when calling flextable() - so if you add headers or footers to the array, they will not be formatted with the theme.

You can also use the post_process_html argument of set_flextable_defaults() (or post_process_pdf, post_process_docx, post_process_pptx) to specify a theme to be applied systematically before the flextable() is printed; in this case, don't forget to take care that the theme doesn't override any formatting done before the print statement.

Examples

ft <- flextable(head(mtcars*22.22))
ft <- theme_apa(ft)
ft
#> a flextable object.
#> col_keys: `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb` 
#> header has 1 row(s) 
#> body has 6 row(s) 
#> original dataset sample: 
#>                       mpg    cyl    disp      hp    drat      wt     qsec    vs
#> Mazda RX4         466.620 133.32 3555.20 2444.20 86.6580 58.2164 365.7412  0.00
#> Mazda RX4 Wag     466.620 133.32 3555.20 2444.20 86.6580 63.8825 378.1844  0.00
#> Datsun 710        506.616  88.88 2399.76 2066.46 85.5470 51.5504 413.5142 22.22
#> Hornet 4 Drive    475.508 133.32 5732.76 2444.20 68.4376 71.4373 431.9568 22.22
#> Hornet Sportabout 415.514 177.76 7999.20 3888.50 69.9930 76.4368 378.1844  0.00
#>                      am  gear  carb
#> Mazda RX4         22.22 88.88 88.88
#> Mazda RX4 Wag     22.22 88.88 88.88
#> Datsun 710        22.22 88.88 22.22
#> Hornet 4 Drive     0.00 66.66 22.22
#> Hornet Sportabout  0.00 66.66 44.44