Open rmflight opened 3 weeks ago
Just to be doubly sure what is causing the error message and malformed tables Word (and it is in Word only, LibreOffice doesn't care, which is a pain to check this because I need to be running a Windows VM), I also hand crafted examples:
The nested tables (which according to other issues seems to intended behavior with automatic captions) seem to be the actual problem. Word complains when the nested tables are present.
See the difference in opening removing bookmark (but keep nested tables) (source) and removing nested tables (source).
Does this happen anywhere else besides gt
tables?
Yes, kable tables seem to suffer the same thing. I think any table with a caption ends up the same way, given it seems to happen for both gt
and kable
with captions both nested tables, and although Word doesn't complain about the kable case, the table still looks wrong, and gets fixed by removing the nested situation.
I could easily add flextable and any other table packages we want to evaluate to triple check that it is the nested tables due to captions.
Are there other table frameworks that should be included?
No, thank you. The reason I asked about gt
was to rule out Quarto's HTML-to-Pandoc processing code, of which only gt
takes advantage, as far as I know.
Yeah, I wanted to check if it was a gt
issue only, so I made sure to check it all with another table generator, and then also see what happened when I hand tweaked the XML for it as well.
Just for funsies, I did check with a flextable
as well.
Word still complains, but in contrast to gt
and kable
, the table still looks OK in the recovered document.
And then again, removing the nested table structure by hand massaging the XML and creating a new document with it, Word stops complaining about the document.
Just for information if it may help debugging it also works and without complaints from Word with tinytable
.
@katossky In my testing, you are right. However, none of the styling applied seems to show up in the Word document either. See this commit: https://github.com/rmflight/gt_quarto_table_weirdness/commit/da43fd471babc7b76fdea72ea11731286c8d8142
Bug description
I've created a repo that documents the issues encountered in trying to create cross-referenced tables in a qmd document output to Word.
I realize that solving the cross-referenced XML issue is difficult if one doesn't know what bad XML is causing the issue, and what the good XML looks like, so I worked to figure it out.
These have been confirmed using:
Problem
When creating a Word document with a cross-referenced table included, the table XML becomes malformed, and Word complains bitterly, and the tables don't look right.
Resources
The repo has an R file with 3 functions:
unzip_reformat
: unzips the docx and then prettifies the XML to make it legible by human eyes.reformat
: actually does the reformatting of the docx.create_docx
: given a zip directory, create a docx file from it, so one can test if modified XML results in a nicer docx file.qmd files to provide reproducible examples of things not working, as well as the corresponding docx files:
gt_good_xml.qmd
: no cross-reference, just works when opened in Word.gt_bad_xml.qmd
: has a single table cross reference, Word complains when opened, table looks weird.kable_okish_xml.qmd
: uses kable to generate the table, and has a cross-reference. Word does not complain, but table looks malformed.Issue
Examining the XML from the files above, we can discover some weird XML created when cross-references are auto generated (whether gt or kable are used to generate the table):
Solution
I've hand crafted the XML in the
_modified_to_work
directories, and then created corresponding docx files, and verified that the links do work between text and caption, Word no longer complains, and the tables look better.Related to #7151 , #9650
Steps to reproduce
No response
Expected behavior
No response
Actual behavior
No response
Your environment
Quarto check output