quarto-dev / quarto-dev/quarto-cli
table cross references result in malformed xml
@cderv is already working on this.
Since Jul 22, 2026.
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
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:
R 4.3.0 (running on Pop!OS)
quarto 1.6.5
Word 2019
Windows 10 Education
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):
- The creation of a nested table, where the first starts before the caption, and then the next table is within the first one.
- The bookmark that defines where to link to the caption, is actually wrapped around the entire second table (start loc, end loc), instead of just the caption text.
Solution
- Make sure only a single table is defined, after the table caption (see modified example).
- Create the bookmark only around the table caption (see modified example).
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
- IDE: 2024.07.0 Build 145
- R Version: 4.3.0
- OS: Pos!OS (Ubuntu based Linux)
Quarto check output
Quarto 1.6.5
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.2.0: OK
Dart Sass version 1.70.0: OK
Deno version 1.41.0: OK
Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.6.5
Path: /opt/quarto/bin
[✓] Checking tools....................OK
TinyTeX: (external install)
Chromium: (not installed)
[✓] Checking LaTeX....................OK
Using: TinyTex
Path: /home/rmflight/.TinyTeX/bin/x86_64-linux
Version: 2022
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK
Version: 3.10.12
Path: /usr/bin/python3
Jupyter: (None)
Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter
(/) Checking R installation...........→ R version 4.3.0 (2023-04-21)
→ Running under Pop!_OS 22.04 LTS
(|) Checking R installation...........→ System time is 2024-08-22 09:25:08.269918
[✓] Checking R installation...........OK
Version: 4.3.0
Path: /rmflight_stuff/software/R-4.3.0
LibPaths:
- /rmflight_stuff/software/R-4.3.0/library
knitr: 1.42
rmarkdown: 2.21
[✓] Checking Knitr engine render......OK
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.