https://forum.posit.co/t/table-captions-not-displaying-when-rendering-quarto-to-word/163331?u=poser92

Hi, I'm having the same issue which was brought up in the question linked in the title.
I need to render some table in a word document but my table caption disappears once the document is rendered
here's my code


title: "Table example"
format:
docx
editor: visual

#| echo: false
#| label: table_1

library(tidyverse)
library(gtsummary)
library(gt)

mtcars %>% 
  tbl_summary() %>% 
  as_gt() %>%
  tab_caption(caption = md("Table caption"))

any suggestions?
@cderv @rich_i

thanks in advance

Try

#| echo: false
#| label: table_1
mtcars %>% 
  tbl_summary() %>% 
  as_gt() %>%
 tab_header(title = "Table caption")

This works in PDF but seems to add an extra "X" in Word.

It seems to work as word document using tab_header(title = "Table caption") (although I don't like the formatting) but now every table of the document has "table 1" before "table caption" and I can't figure out where this "table1" comes from.
Here's my code

#| echo: false
#| label: table
#| tbl-cap: table

library(tidyverse)
library(gtsummary)
library(gt)

mtcars %>% 
  tbl_summary() %>% 
  as_gt() %>%
 tab_header(title = md("**Table caption**"))

and here's the output

Interesting. I an a Linux user and do not have Word but LibreOffice. Here is what I am getting

Do you have to use {gt} ? Another package, maybe {flextable} might be appropriate.

I have to leave now but I'll try to look at this later today.

I have issues with flextable either. I'm definitely missing something about table rendering in quarto documents!
In any case, thanks for your suggestions!

Maybe just remove the

#| label: table
#| tbl-cap: table
---
title: ""
format: docx
---

```{r load}
#| echo: false
#| include: false

library(tidyverse)
library(gtsummary)
library(gt)

It was a dark and stormy night.

#| echo: false
mtcars %>% 
  tbl_summary() %>% 
  as_gt() %>%
 tab_header(title = "Table caption")

It doesn't work anyway :sleepy:

Why not?
Do you get any error messages? If so can you post them here?
thanks

These are my codes

title: ""
format: docx
#| echo: false
#| include: false

library(tidyverse)
library(gtsummary)
library(gt)
#| echo: false
mtcars %>% 
  tbl_summary() %>% 
  as_gt() %>%
 tab_header(title = "Table caption")

this is the output

Screenshot 2023-10-24 at 13.27.54

Blast it, I ran it in .pdf not .docx and it looked okay. I'm at a loss here.

If it is possible in Word, I'd just create a new style and manually edit the table caption in Word . My results doing this in LibreOffice.

You might want to e-mail the package author/maintainer mentioning this problem. It could be a package problem or a Pandoc issue.

Most of the people I work with want to revise docx document so I would like to find my setup with this format. So far it is kind of frustrating.

Yes I see the problem. I do think the best idea is an email to the author/maintainer. I 'think' that it likely is a pandoc problem since I am getting a clean pdf version. They may be able to confirm this and suggest what to do.

I believe you are just encountering some issues with cross referencing, and Docx document.
Follow the work happening in Quarto for 1.4 and it will be solved.

you could try pre-release already: Quarto - Pre-release Builds

There are already several issues about gt and flextable for docx output with Quarto so you should find some reading if you want at GitHub - quarto-dev/quarto-cli: Open-source scientific and technical publishing system built on Pandoc.

Thanks for your patience while we are improving all this.

1 Like

Something must have been fixed because, using same codes as before, I get properly numbered table when I rented docx using quarto

Interesting I'm still getting

Table 1: Table captionX

in LibreOffice in Ubuntu. Come to think of it, I use LO so seldomly I probably need to update it.

Is this using the latest pre-release 1.4 ?

Dear @cderv I would like to ask a different question.
I see that by default a docs (or whatever format) rendered with quarto is stored in the same folder of the .qmd file.
Is there a way to tho set the output on a different folder? I've tried to use output-dir but with no success

Thanks

output-dir only work on project.

Easiest way to render in another directory is to manually move it after rendering.

Quarto projects also have a Post render script feature to help with such post render tasks: Quarto - Project Scripts

Hope it helps

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.