davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
561 stars 81 forks source link

set_caption does not work when rendered in quarto, but does with print() command #570

Closed mlamias closed 8 months ago

mlamias commented 1 year ago

It seems that set_caption does not appear to be working (for me, at least) when rendering in Quarto to a Word document using the following yaml header:

---
project:
  title: "Test"
format: docx

editor: visual
---

I have the following code in my .qmd file:

```{r}
#| echo: false
cars |> flextable() |> 
flextable::set_caption("THIS TEST")


Unfortunately, this seems to produce the following in my Word document:
![image](https://github.com/davidgohel/flextable/assets/9097516/1ea0bd5b-869d-4e49-be05-a35a69921ad0)

However, if I issue the following statement in R console:

`cars |> flextable() |> set_caption("THIS TEST") |>  print(preview="docx")`

I obtain the following Word document which produces the appropriate caption above the table:
![image](https://github.com/davidgohel/flextable/assets/9097516/39f589fd-ece1-4258-8bbe-ddd9631c5490)

I assume this should work since the [`set_caption()` documentation](https://davidgohel.github.io/flextable/reference/set_caption.html) reads:

> When working with 'R Markdown' or 'Quarto', the caption settings defined with `set_caption()` will be prioritized over `knitr` chunk options.

Is this a bug with `flextable`, `Quarto`, or am I missing something?
davidgohel commented 1 year ago

It's a missing feature in Quarto. See https://github.com/davidgohel/flextable/issues/565#issuecomment-1695118970, https://github.com/davidgohel/flextable/issues/494, https://github.com/quarto-dev/quarto-cli/issues/1556, https://davidgohel.github.io/flextable/reference/set_caption.html#using-quarto-, https://ardata-fr.github.io/flextable-book/captions-and-cross-references.html#cross-references

Captions will work in Quarto with HTML and PDF but not Word.

mlamias commented 1 year ago

Thanks @davidgohel. Sorry I missed this in the documentation. I did read through several pages and through opened cases, but I totally missed these. Thanks for pointing this out. I really appreciate the assist.

davidgohel commented 8 months ago

This issue can be closed, captions seem to work as expected with Quarto 1.4.549.

For future readers, TLTR, set_caption() has not effect with Quarto that manage captions on its own.

github-actions[bot] commented 2 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.