knitr::opts_chunk$set(echo = FALSE)
library(flextable)
library(magrittr)
library(officer)
caption_md <- "This is a caption"

knitr::opts_chunk$set(ft.shadow = FALSE,
  tab.lp = "tab:", 
  tab.cap.style = "Table Caption")

ft <- flextable(head(cars)) %>% 
  theme_vanilla() %>% 
  autofit()

Cross-reference is there: \@ref(tab:id1)

A caption, no id

ft

A caption and an id

ft

No caption and an id

ft

Using set caption

#| tab.topcaption: true
set_caption(
  x = ft, 
  caption = as_paragraph(
      as_chunk("azerty ", props = fp_text_default(color = "cyan")),
      as_chunk("querty", props = fp_text_default(color = "orange"))
  ),
  autonum = run_autonum(seq_id = "tab", bkm = "id2"),
  fp_p = fp_par(
    padding = 10, 
    border = fp_border_default(color = "red", width = 1))
)

Using set caption and chunk options

#| tab.topcaption: false
set_caption(
  x = ft, 
  caption = as_paragraph(
      as_chunk("azerty ", props = fp_text_default(color = "cyan")),
      as_chunk("querty", props = fp_text_default(color = "orange"))
  )
)


davidgohel/flextable documentation built on April 18, 2024, 11:37 a.m.