I'm using officer
and flextable
to create captioned tables in a report exported to word. I've been setting "Table Caption" as the word style, and indeed the exported word doc has the caption identified as the style "Table Caption". However, the title section of the caption does not follow the set word style. The "Table #:" part does, but the caption words do not. The caption words show up as Arial. If I change the flextable font via set_flextable_options
, the caption words will be in that font.
The same result occurs regardless of how the caption is set, i.e. via tab.cap
and tab.cap.style
or via set_caption
. I made a new word style in case something was weird with the default "Table Caption" and used that in tab.cap.style
and the same thing happens. It shows as set to that style but doesn't follow the font properties of the style. The "Table #:" part comes out as expected.
Example:
---
title: "flextable caption example"
output:
officedown::rdocx_document:
reference_docx: ref.docx
---
```{r setup, include=FALSE}
library(officedown)
library(officer)
library(flextable)
knitr::opts_chunk$set(
echo = FALSE,
tab.cap.style = "Table Caption",
tab.cap.pre = "Table",
tab.cap.sep = ":")
```
```{r echo=FALSE, tab.cap="airquality dataset", tab.id="tab1"}
ft <- qflextable(head(airquality))
ft
```
The image is with "airquality dataset" selected. Expected output would be for the entire caption to be in the same style as "Table 1:" is.
My search hasn't come across any instance of this issue, and from following the online user guides I believe I am doing it correctly. In fact, running sample code from online does the exact same thing.
If I'm missing something, please let me know. Or if there's another way to set the caption font properties other than identifying a word style.
I was having this same issue, but it resolved when I reinstalled the flextable package on 11/18/2022. Now, both the figure and table captions in the knitted Word doc appear correctly bolded. (The reinstall also fixed a problem I was having with tables breaking across pages correctly.) Hope this helps!