Skip to content

Fix table widths: ignore nested rows and update cell widths - #206

Merged
cvas22 merged 1 commit into
mainfrom
fix/64-11-fix-tables-widths
Nov 25, 2026
Merged

cvas22 merged 1 commit into
mainfrom
fix/64-11-fix-tables-widths

Conversation

@cvas22

@cvas22 cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Two problems in fix_tables():

  • It walked t.iter("w:tr"), which includes the rows of tables nested in the cells. A 2-column table holding a 4-column table ended up with 4 grid columns and rescaled widths, even with no tags at all. That's very likely what Function fix_tables resets tables configured in Libreoffice Writer #64 hit with the LibreOffice template. It now only looks at the table's own rows, and nested tables are still fixed on their own pass. Tables without a tblGrid are skipped instead of raising.
  • When the grid did change, the cells kept their old w:tcW, and Word uses that over the grid, so after {%tc for %} added columns the table got narrower (Table width becomes narrower after render #11). When the grid is resized, each dxa cell width is now set to the sum of the grid columns it spans. Percentage and auto widths are left alone.

Tables whose grid isn't touched come out exactly as before.

The new tests check that a nested table leaves the outer grid alone, and that after adding columns every cell width matches its grid column and the total stays the same. Both fail on main. I checked the XML only, not the rendering in Word or LibreOffice.

Fixes #64
Fixes #11

fix_tables() walked every w:tr under a table, so a nested table's rows
counted towards the outer table's column count and its grid got rescaled
for nothing. Only look at the table's own rows now.

When the grid does change, e.g. after {%tc for %} adds columns, each
cell's w:tcW is now set to the width of the grid columns it spans. Word
prefers tcW over the grid, so the old widths left the table narrower.

Fixes #64
Fixes #11
@github-actions github-actions Bot added code Changes to the docform package tests Changes to tests labels Nov 25, 2026
@cvas22
cvas22 merged commit 9f69fff into main Nov 25, 2026
11 checks passed
@cvas22
cvas22 deleted the fix/64-11-fix-tables-widths branch November 25, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Changes to the docform package tests Changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function fix_tables resets tables configured in Libreoffice Writer Table width becomes narrower after render

1 participant