Add a legend to a table or a figure in an officer document. Legends can be referred to using the @ref syntax in body_add_normal() (see examples for some use cases). Table legends should be inserted before the table while figure legends should be inserted after the figure.
legend: the table legend. Supports glue syntax and markdown syntax (see Section below).
...: unused
bookmark: the id of the bookmark. This is the id that should then be called in body_add_normal() using the "\\@ref(id)" syntax. Forbidden characters will be removed.
legend_style: style of of the whole legend. May depend on the docx template. However, if name_format is provided with a specific font.size, this size will apply to the whole legend for consistency.
style: deprecated in favor of name_format.
legend_prefix: a prefix that comes before the legend, after the numbering
name_format: format of the legend's LHS (legend_name + numbering) using officer::fp_text_lite() or officer::fp_text(). Default to fp_text_lite(bold=TRUE) in addition to the format defined in legend_style. Note that the reference to the bookmark will have the same specific format in the text.
legend_name: name before the numbering. Default to either "Table" or "Figure".
seqfield: Keep default. Otherwise, you may figure it out doing this: in a docx file, insert a table legend, right click on the inserted number and select "Toggle Field Codes". This argument should be the value of the field, with extra escaping.
par_before, par_after: should an empty paragraph be inserted before/after the legend?
envir: Environment to evaluate each expression in glue().
legacy: use the old version of this function, if you cannot update {officer} to v0.4+
Returns
The docx object doc
Warning
Be aware that you unfortunately cannot reference a bookmark more than once using this method. Writing:
body_add_normal("Table \\@ref(iris_col1) is about flowers. I reallylike Table \\@ref(iris_col1).")
will prevent the numbering from applying.
What to do if there is still no numbering?
During the opening of the document, MS Word might ask you to "update the fields", to which you should answer "Yes".
If it is not asked or if you answer "No", the legends added with body_add_table_legend() or body_add_figure_legend() might have no actual numbers displayed.