Skip to content

Typst: measure indent and spanning cells in note-table column widths (#695) - #696

Merged
vincentarelbundock merged 1 commit into
mainfrom
typst-widths-695
Nov 16, 2026
Merged

vincentarelbundock merged 1 commit into
mainfrom
typst-widths-695

Conversation

@vincentarelbundock

Copy link
Copy Markdown
Owner

Closes #695.

Problem

In Typst tables with notes, typst_widths() measures each column's natural width from a plain grid of its cells, then converts the widths to fr units. That measurement had two bugs:

  1. Indent was ignored. The plain grid bypasses the show table.cell rule that applies pad(left: indent), so indented cells overflowed into the next column (the overlap with short group labels).
  2. Spanning group labels counted toward every column. @data_body already contains the group_tt(i =) rows, so each label was measured as content of every column. Long labels inflated all columns and pushed the table to the page-width cap, which made headings wrap. This also hid bug 1.

Fix

  • New helper typst_measure_cells():
    • Measures each cell with its resolved indent (from @style_other, so column-wide settings and last-write-wins are respected).
    • Skips cells that span several columns, and cells hidden under a span.
    • Group rows inserted with group_tt(i =, j = <matrix>) are still measured per column.
  • Spanning cells (group labels, header colspans, style_tt(colspan =)) are measured separately. The columns they cover grow in proportion only when a span does not fit, so long labels don't wrap.
  • Only the notes path changes. Tables with auto or explicit widths are unaffected.

Tests

  • Regression tests in inst/tinytest/test-typst.R: spans excluded, indent measured (cell-level and column-wide), indent = 0 override, matrix-inserted rows, and empty theme with notes.
  • Three Typst snapshots regenerated. The diffs are boilerplate only (trailing commas plus an empty span loop), and the measured content is unchanged.
  • The full tinytest suite passes. Two Roborev passes: the first found two bugs, which are fixed; the second passed.

Known limitation

When the natural width exceeds the page width, all columns shrink proportionally, so headers may wrap slightly. Bold and font size are still not counted in the measurement.

🤖 Generated with Claude Code

…695)

With notes, Typst column widths are measured from a plain grid of each
column's cells. That measurement ignored style_tt(indent = ), so indented
cells overflowed into the next column, and it counted full-width
group_tt(i = ) labels as content of every column, inflating all columns.

- Measure each cell with its resolved indent (from @style_other).
- Skip cells that span several columns, and cells hidden under a span.
- Measure spanning cells separately and widen the covered columns
  proportionally only when a span does not fit.
- Matrix-inserted group rows keep per-column measurement.

Closes #695

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vincentarelbundock
vincentarelbundock merged commit 7972e1a into main Nov 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Short group labels "breaks" the table layout

1 participant