| apa_style | R Documentation |
flextable::flextable object according to APA styleapa_style() applies the fonts, rules, spacing, and alignment of an APA-style
table to a flextable and converts markdown in its cells. apa_flextable()
calls it, so it is needed only for a flextable made some other way.
apa_style(
x,
font_family = NULL,
font_size = NULL,
text_color = "black",
border_color = "black",
border_width = 0.5,
line_spacing = NULL,
horizontal_padding = 3,
table_align = "left",
header_align_vertical = c("top", "middle", "bottom"),
layout = "autofit",
table_width = NULL,
markdown = TRUE,
markdown_header = markdown,
markdown_body = markdown,
no_markdown_columns = NULL,
no_markdown_columns_header = no_markdown_columns,
separate_headers = TRUE
)
x |
a |
font_family |
font family (e.g., |
font_size |
font size, in points. If |
text_color |
color of the text: an R color name (e.g., |
border_color |
color of the rules, in the same forms as |
border_width |
width of the rules, in points (default: 0.5) |
line_spacing |
spacing between lines of the header and body (e.g., 2
for double spacing or 1 for single spacing). If |
horizontal_padding |
space to the left and right of each cell's contents, in points (default: 3) |
table_align |
alignment of the table on the page: |
header_align_vertical |
vertical alignment of header text when header
cells differ in height: |
layout |
|
table_width |
width of the table, in the same forms in every apa7
function: a proportion from 0 to 1 of the default width (the full width
of a portrait page unless changed with |
markdown |
if |
markdown_header, markdown_body |
whether the header or the body is
converted from markdown (both default to |
no_markdown_columns |
body columns whose text is shown as it is, not converted from markdown (unquoted or quoted names, or tidyselect helpers) |
no_markdown_columns_header |
column headers that are not converted
from markdown. By default, the same columns as |
separate_headers |
if |
With a few minor details omitted, apa_style() does roughly this:
Separates the headers into column spanners and deckered heads at
underscores, if separate_headers = TRUE and the header has one row.
Sets the font, font size, and text color of every cell.
Draws the three horizontal rules of an APA table: above the header, below the header, and below the body.
Top-aligns the body cells, centers the header text, and aligns the
header cells vertically with header_align_vertical.
Adds space above and below each cell's text, (line_spacing - 1) times
2/3 of the font size, so that rows have the spacing of line_spacing
while text that wraps within a cell stays single-spaced. In Typst output,
the space is a little larger, because Typst measures lines differently
than Word does. The left and right padding is horizontal_padding.
Styles apa7's helper columns. Break columns (from add_break_columns())
are left empty. Star columns (from add_star_column() and
separate_star_column()) and list columns (from add_list_column()) have
no header and no padding on the side next to the column they belong to,
so that the two read as one column.
Sets the table's layout, alignment on the page, and width (layout,
table_align, and table_width). In Word, the table is kept on the same
page as the text that follows it.
Converts markdown in the header and the body with
ftExtra::colformat_md(), except in the columns named in
no_markdown_columns_header and no_markdown_columns and in cells that
are already formatted.
If the first column is named Variable or Predictor, left-aligns it.
flextable::flextable
American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1037/0000165-000")}
d <- data.frame(x = 1:3, y = 4:6)
flextable::flextable(d) |>
apa_style()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.