-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Captions & crossrefs not rendering in Quarto with Flextable #1556
Comments
I see the same problem with flextable for PDF output also. Example on RStudio Cloud https://rstudio.cloud/content/4327822 A similar problem appears with {gt} in PDF. But in this case the caption appears but the Table 1 part does not. It looks ok in Word however. --- title: "test" format: pdf: default html: default docx: default --- # flextable Reference @tbl-flextable ```{r} #| label: tbl-flextable #| tbl-cap: "Caption 1" library(flextable) flextable(head(mtcars)) ``` # gt Reference @tbl-gt ```{r} #| label: tbl-gt #| tbl-cap: "Caption 2" library(gt) gt(head(mtcars[,1:3])) ``` RStudio version on cloud is 2022.02.2 but I see the same problem on my laptop (M1 Mac) with RStudio 2022.07.1+554 |
The problem is that flextable is creating raw openxml output for the table which Quarto doesn't know how to parse/interact with (we can do this for raw HTML and raw LaTeX just not raw openxml. A possible solution would be to fallback to a div which contains the table and just implements the caption manually (i.e. not actually the openxml table caption but just text appearing above or below). We'll take a look at doing this for our v1.2 release. |
Ah right. That's why flextable works so nicely with Word; it creates raw openxml. |
I'm hoping any caption/crossref solution includes making the auto-numbering work as well |
Most of the issues should be now fixed for flextable and quarto (in the github version). The limit for now is in the docx version. There is no caption generated by Quarto as explained upper. flextable manages it but as a result, cross-referencing is not possible with the syntax (@tbl-dudu). If there is a solution later, I will adapt the code. As a workaround, use
The HTML code can contain a caption, but it will be rewritten by Quarto with the values of the R chunk parameters, same for the PDF version. I think that Quarto's support imposes to prefer the values linked to the captions defined in the chunk options rather than the values defined with |
That's too bad re docx output. For my agency (NOAA), we use flextable because it works so well with docx. I have not found another table generating package that works as seamlessly, meaning looks good by default. For PDF and HTML, there are a number of other good table generating packages. Any sense of which table package that Quarto will best support going forward? Given that supporting every package out there might be untenable? Which table package doesn't matter so much, rather it is the cross-format support that is key: looks equally good in HTML, PDF and docx (without changing the table code) and cross-refs/captions work across all formats. Fancy table widgets and formatting (colors and stripes stuff) is not important. Just need solid scientific table support (captions, footnootes, footer notes, landscape option (docx and PDF), and reasonable auto-scaling and table breaking across pages (docx and PDF). |
We will certainly try to maintain strong support for all popular table package. In addition, we are investing aggressively in the gt package (in fact its maintainer @rich-iannone has recently joined the Quarto team to focus on among other things gt and tables more broadly in the Quarto ecosystem). |
Good to know re {gt} package. We (NOAA R users admins) have talked about encouraging a switch to {gt}. But last info I saw (June? 22) https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html was that {gt} still not fully supporting docx. Then again, that's from the {gtsummary} vignette not {gt}. |
docx output in gt |
@cscheid , does that mean if I install the development version of |
I'm going to push a full fix for this to 1.3, since we'll be adding native AST types for tables, etc. and we should start working on communicating better with downstream libraries. |
I was able to compile a Word document using Quarto with one flextable. However, the rendering hangs when I add a second flextable (see example below). I'm working with the most recent development version of Quarto, and RStudio (2022.07.1) and flextable (flextable_0.8.3.012) are up-to-date.
|
@kjell-stattenacity I can reproduce that locally, and that's different, it's actually a bug. Thanks for the report! I'll open a separate issue. |
I think this issue is fixed in flextable since few months. Can this issue be closed? |
@davidgohel your previous message said this:
I would prefer to keep this issue open so that we can handle the crossref syntax issue better on quarto's end. |
@cscheid OK, thanks. I'd like to have the same behavior as with the other formats. If I should change something with captions in Word for Quarto, let me know (I don't know if I did the right thing!) |
You can produce tables, but, unfortunately, you can't format them Hopefully soon? |
Hi all, is there any update for |
@sgvignali we're going to do this work in 1.4, as I indicated on the milestone change. |
For reference to follow work across repo, this is also tracked in flextable directly at davidgohel/flextable#494 |
@davidgohel I don't think the workaround you gave above works any more? Here's the Word output I get from the same code with Quarto 1.3.333, Flextable 0.9.1, Officer 0.6.2 and Officedown 0.3.0. It seems to copy the entire table where the cross-reference should be and there are issues with the table captions. |
Hi @aaronschiff, did you come up with a work-around for this one? I have the same issue. |
@BMC1986 no I didn't, sorry. For now I had to stop producing Word output and wait for a future fix in Quarto. PDF output works fine so I am using that in the meantime. |
Just to clarify, neither flextable nor gt can currently handle cross-referencing in Word, correct? We're waiting on a Quarto update? That is what I'm noticing but want to make sure I haven't missed a workaround. The only way I can seem to get any table cross-referencing in Word is |
Any progress on this? The gt documentation suggests it works - but it definitely doesn't for me. |
@schwa021 since the issue here is really about flex table, please open a new GitHub Discussion with a "working" reproducible example. To note, flextable/gt do a lot of processing and do not output markdown which basically disable some markdown-based feature. |
With the current 1.4 prereleases, the following almost works.
Produces a document that Microsoft Word doesn't appear to like. But if you tell it to try to open the file anyway, you should see this: The remaining issue with Microsoft Word will be handled on #7321. |
Bug description
Description
When rendered via Quarto with output format as docx, caption (tbl-cap) and crossref (@tbl-ref) not working with flextable.
Reproducible example
See output docx file: mwe_book.docx
This issue is also mentioned here on flextable github page: flextable Github page
Expected result
Caption and crossref should render correctly in Word doc
RStudio information
OS information
Windows 10 Enterprise
quarto check
Outputquarto tools check
Output[>] Inspecting tools Tool Status Installed Latest chromium Not installed --- 869685 tinytex External Installation --- v2022.07
Checklist
quarto check
in the "Quarto Check Output" text area?quarto tools check
in the "Quarto Tools Check Output" text area?The text was updated successfully, but these errors were encountered: