Learn R Programming

flextable (version 0.7.2)

set_caption: Set Caption

Description

Set caption value in a flextable.

  • The caption will be associated with a paragraph style when the output is Word. It can also be numbered as a auto-numbered Word computed value.

  • The PowerPoint format ignores captions.

Usage

set_caption(
  x,
  caption,
  autonum = NULL,
  style = "Table Caption",
  html_escape = TRUE
)

Arguments

x

flextable object

caption

caption value

autonum

an autonum representation. See officer::run_autonum(). This has only an effect when output is Word. If used, the caption is preceded by an auto-number sequence. In this case, the caption is preceded by an auto-number sequence that can be cross referenced.

style

caption paragraph style name. These names are available with function officer::styles_info() when output is Word; if HTML, the value is set as class value in the caption tag.

html_escape

should HTML entities be escaped so that it can be safely included as text or an attribute value within an HTML document.

R Markdown

flextable captions can be defined from R Markdown documents by using knitr::opts_chunk$set(). The following options are available with officedown::rdocx_document and/or bookdown:

labelnamevalue
Word stylename to use for table captions.tab.cap.styleNULL
caption id/bookmarktab.idNULL
captiontab.capNULL
display table caption on top of the table or nottab.topcaptionTRUE
caption table sequence identifier.tab.lp"tab:"

The following options are only available when used with officedown::rdocx_document:

labelnamevalue
prefix for numbering chunk (default to "Table ").tab.cap.preTable
suffix for numbering chunk (default to ": ").tab.cap.sep" :"
title number depthtab.cap.tnd0
separator to use between title number and table number.tab.cap.tns"-"
caption prefix formatting propertiestab.cap.fp_textfp_text_lite(bold = TRUE)

See knit_print.flextable for more details.

See Also

flextable()

Examples

Run this code
ftab <- flextable( head( iris ) )
ftab <- set_caption(ftab, "my caption")
ftab

library(officer)
autonum <- run_autonum(seq_id = "tab", bkm = "mtcars")
ftab <- flextable( head( mtcars ) )
ftab <- set_caption(ftab, caption = "mtcars data", autonum = autonum)
ftab

Run the code above in your browser using DataLab