Docx writer: zero-width gridCols for tables mixing explicit and default column widths

#11899 · closed · 0 comments

View on GitHub ↗

sghng

**Explain the problem.** A table whose column specs mix explicit `ColWidth` values with `ColWidthDefault` gets a `w:gridCol w:w="0"` for every unspecified column. Word and LibreOffice honor the zero widths literally, so those columns collapse to nothing (or render as hairlines) under the fixed table layout the writer emits. **Reproduce** (stock pandoc; the AST is reachable from any reader that leaves widths unspecified, here via native input): ```sh cd $(mktemp -d) cat > t.native <<'EOF' [ Table ( "" , [] , [] ) (Caption Nothing []) [ ( AlignDefault , ColWidth 0.4 ) , ( AlignDefault , ColWidthDefault ) ] (TableHead ( "" , [] , [] ) [ Row ( "" , [] , [] ) [ Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "A" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "B" ] ] ] ] ) [ TableBody ( "" , [] , [] ) 0 [ Row ( "" , [] , [] ) [ Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "1" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "2" ] ] ] ] ] (TableFoot ( "" , [] , [] ) [] ) ] EOF pandoc t.native -o t.docx unzip -p t.docx word/document.xml | grep -o '<w:gridCol[^/]*/>' ``` **Received:** ``` <w:gridCol w:w="3168" /> <w:gridCol w:w="0" /> ``` **Expected:** unspecified columns are sized from their content. The table should carry a 100 percent `w:tblW` (`pct=5000`) with `w:tblLayout type="autofit"` and equal grid values as hints, letting the layout engine do its job, as it does for tables with no explicit widths at all. **Root cause:** `tableLayout` in `src/Text/Pandoc/Writers/Docx/Table.hs` has two modes, all-default (`autofit`, equal hints) and has-widths (fixed layout, computed `gridCol`s); a mixed table falls into the has-widths branch, and the default columns contribute `0` to the grid. **Fix:** detect the mixed case and take the autofit path with `tblW pct=5000`; all-explicit and all-default tables are unchanged (coverable with a golden test). Pairs with the reader issue about auto columns being averaged: once a reader leaves widths unspecified, every such table lands here. > [!NOTE] > > This is 9/13 of issues identified in an attempt to create an APA styled Word target from a Typst source. The issues are ordered logically so that fundamental fixes are applied first. I have fixed all of them locally and will split and upstream the fixes one by one.

Comments