Skip to content

fix(tables): expand auto-width tables to fill available page width#2109

Open
tupizz wants to merge 2 commits intomainfrom
tadeu/fix-auto-table-width-fill-page
Open

fix(tables): expand auto-width tables to fill available page width#2109
tupizz wants to merge 2 commits intomainfrom
tadeu/fix-auto-table-width-fill-page

Conversation

@tupizz
Copy link
Contributor

@tupizz tupizz commented Feb 19, 2026

Summary

Closes SD-1956 https://linear.app/superdocworkspace/issue/SD-1956/bug-auto-layout-tables-with-explicit-tblgrid-tiny-tcw-render-squished

  • Tables without explicit w:tblW (or with type="auto") were rendering at ~1/3 page width instead of filling the available content area like Microsoft Word does
  • Root cause was in the measuring-dom layer: auto-layout tables only scaled down (when too wide) but never up to fill available space
  • Also fixed resolveTableWidth() not recognizing type='dxa' — the most common explicit width type in OOXML — which caused dxa-width tables to incorrectly fall into the auto-layout path

Why this was happening

The table measurement pipeline in measureTableBlock() has two branches:

  1. Explicit width branch (hasExplicitWidth || hasFixedLayout): scales columns both up and down to match the declared table width
  2. Auto-layout branch (no explicit width): only scaled down when columns exceeded available space, but never scaled up — leaving narrow imported column widths as-is

When a DOCX file has no w:tblW element (or type="auto"), resolveTableWidth() returned undefined, so hasExplicitWidth was false. The auto-layout branch would receive narrow column widths from the import (e.g., 100px per column from w:tcW cell widths or the fallback grid), and since the total was less than the page width, no scaling occurred.

Additionally, resolveTableWidth() only recognized type='pct' and type='px'/'pixel', but not type='dxa' — even though dxa values are already converted to pixels during import by the tbl-translator. This meant tables with explicit dxa widths also fell into the auto-layout path.

What we changed to prevent this

  1. Scale up auto-layout tables (ECMA-376 §2.4.64): When a table has no explicit width, the layout algorithm (§2.4.49/§2.4.50) uses autofit, which in practice expands the table to fill the available page content width. The auto-layout branch now scales columns proportionally in both directions to match this behavior.

  2. Handle dxa type in resolveTableWidth(): Added type='dxa' alongside 'px'/'pixel' so that tables with explicit dxa widths are correctly recognized as having an explicit width, preventing them from being affected by the auto-layout scale-up.

Test plan

  • All 224 measuring-dom tests pass (updated 12 existing tests to reflect new auto-layout behavior)
  • All 663 super-editor test files pass (6162 tests)
  • All 474 layout-engine tests pass
  • TypeScript typecheck passes
  • Visual verification: load AI-generated DOCX with auto-width tables → tables fill page width
  • Visual verification: existing DOCX files with explicit table widths render unchanged

Tables without explicit w:tblW (or with type="auto") were rendering at a
fraction of the page width instead of filling the available content area
like Word does.
Copilot AI review requested due to automatic review settings February 19, 2026 11:06
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes table layout behavior for auto-width tables in the measuring-dom layer. Previously, tables without explicit width (or with type="auto") only scaled down when too wide but never scaled up to fill available space, resulting in tables rendering at approximately 1/3 page width instead of filling the content area like Microsoft Word does.

Changes:

  • Added type='dxa' recognition in resolveTableWidth() to correctly identify DXA-width tables as having explicit width
  • Modified auto-layout branch to scale columns both up and down proportionally to fill available page width, following ECMA-376 autofit behavior
  • Replaced the complex scaleColumnWidths() function with inline scaling logic that uses simpler last-column rounding adjustment

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/layout-engine/measuring/dom/src/index.ts Added 'dxa' type handling in resolveTableWidth(), removed scaleColumnWidths() helper function, updated auto-layout branch to scale columns proportionally to fill available width
packages/layout-engine/measuring/dom/src/index.test.ts Updated 12 test expectations to reflect new auto-layout behavior where tables expand to fill available width

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@linear
Copy link

linear bot commented Feb 19, 2026

…to full page width

Updated the table measurement logic to prevent scaling up column widths when explicit widths are defined. Adjusted tests to reflect the new behavior where tables without explicit widths default to filling the available page content width, aligning with Word's autofit behavior.
@tupizz tupizz self-assigned this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments