Skip to content

fix: keep side-by-side ruled tables separate - #392

Open
Chengyunlai wants to merge 2 commits into
run-llama:mainfrom
Chengyunlai:codex/fix-separated-grid-components
Open

fix: keep side-by-side ruled tables separate#392
Chengyunlai wants to merge 2 commits into
run-llama:mainfrom
Chengyunlai:codex/fix-separated-grid-components

Conversation

@Chengyunlai

@Chengyunlai Chengyunlai commented Jul 31, 2026

Copy link
Copy Markdown

Summary

This PR now fixes the published side-by-side ruled-table reproduction through
the public Markdown output path:

  • keep horizontal rule segments separated across a whitespace gutter;
  • keep same-y text and nearby table labels associated with their own ruled
    table rectangle;
  • preserve left-to-right order within a side-by-side table band and
    top-to-bottom order across bands;
  • add public-output regression coverage and adjacent non-regressions.

Fixes #414.

Root cause

The visible failure had two stages:

two independent side-by-side grids
-> horizontal segments merged across the gutter
-> one geometry component
-> one merged Markdown table

After the geometry component was fixed, a downstream stage was still wrong:

two geometry components
-> same-y text from both tables grouped into shared projected lines
-> each ruled candidate sees adjacent-table overhang
-> ruled candidates rejected
-> fallback emits one merged table

The earlier version of this PR fixed only the first stage, which is why it did
not fix the document linked in the issue comment.

Fix

The two commits keep the responsibilities explicit:

  1. 9d740a4 changes horizontal segment clustering so collinear segments merge
    only when their x ranges overlap or nearly touch. The row-gap / stacked-grid
    behavior from feat: improve table extraction quality  #394 remains unchanged.
  2. 26b79a6 passes detected ruled-table rectangles into projected-line
    construction. Same-y items owned by different table rectangles cannot
    become one projected line, and table-owned lines are ordered by independent
    table bands before table consumption.

Nearby labels are associated only when at least half of the label width belongs
to exactly one table rectangle and the vertical gap is small. A page-spanning
heading that overlaps multiple tables remains unowned. The patch does not
globally change y tolerance, table-confidence thresholds, or fallback logic.

Public reproduction document

This is a self-authored, synthetic one-page Word-to-PDF document containing no
customer, personal, credential, internal-project, or business-specific data.

The same command was used for all three versions:

lit parse /input.pdf \
  --no-ocr \
  --format markdown \
  --output /results/output.md \
  --quiet

Before / after

Version Geometry Public Markdown
main@2fd644a one merged component one 7-column table with an empty gutter column; headings merged
previous PR head 9d740a4 two components one 6-column fallback table; headings become table cells
current PR head 26b79a6 two components two independent headings and two independent 3-column tables

Current output:

## Release channels

| Channel | Status | Owner |
|---|---|---|
| Stable | Ready | Team A |
| Beta | Testing | Team B |
| Nightly | Active | Team C |

## Support windows

| Region | Window | Contact |
|---|---|---|
| East | Morning | Desk 1 |
| West | Afternoon | Desk 2 |
| Central | Evening | Desk 3 |

Regression coverage

The public Markdown seam tests cover:

  • the published side-by-side shape with independent nearby headings;
  • one wide ruled table remaining one table;
  • vertically stacked ruled tables preserving top-to-bottom order;
  • ordinary two-column prose not becoming a table;
  • one page-spanning heading above two tables remaining page-spanning.

Two focused ordering tests also cover:

  • multiple side-by-side table bands ordered top-to-bottom;
  • three-table overlap that must not form a transitive, incorrectly reordered
    band.

Validation

  • cargo fmt --all -- --check
  • public-output integration tests: 5 passed
  • table-band ordering tests: 2 passed
  • cargo clippy -p liteparse --all-targets: passed with existing repository warnings
  • projection regression tests: 18 passed
  • core library suite in the validation container: 333 passed; the only failure
    was the existing LibreOffice-dependent .doc lifetime test because
    LibreOffice is not installed in that container
  • end-to-end parse of the published PDF: exact expected two-heading,
    two-table output above

Follow-up boundary

A smaller adjacent PDF with two same-y headings above two 3-row x 2-column
tables exposes a separate Markdown heading-continuation heuristic after the
tables are already correctly separated. It is documented with its own public
fixture and negative-test requirements in #418. This PR does not claim to fix
that distinct heading-classification case.

@Chengyunlai

Copy link
Copy Markdown
Author

Thanks for merging #394. Its split_component_at_grid_gaps change appears to cover the stacked-grid case addressed by this PR.

This PR also includes the mirrored case: side-by-side ruled grids that share row coordinates. That case still appears possible because cluster_h_segments merges collinear horizontal segments across whitespace, while #394 only splits components along row gaps.

I can rebase this PR onto the latest main and narrow it to the side-by-side case if that would still be useful.

@logan-markewich

Copy link
Copy Markdown
Contributor

If there is an actual doc this occurs on, happy to make it work

@Chengyunlai

Chengyunlai commented Aug 13, 2026

Copy link
Copy Markdown
Author

Follow-up comment for PR #392

Thanks for asking for an actual document. I ran a local reproduction using a neutral Word document converted to PDF. The document contains only generic release-channel and support-window examples; it has no customer data, credentials, internal project names, or business-specific content.

The PDF contains two independent ruled tables placed side by side. Their horizontal rules use the same y coordinates, with a clear horizontal gutter between the tables.

Compared with the 2.10.1 base commit:

  • the baseline groups the two sets of horizontal segments into one geometry component;
  • PR fix: keep side-by-side ruled tables separate #392 groups them into two independent geometry components;
  • the existing unit tests in this PR cover the corresponding side-by-side component behavior.

This confirms that cluster_h_segments / grid-component part of PR #392 is useful and matches the reported failure mode.

The same end-to-end document also exposed a separate downstream issue: the text projection stage still groups text from the two columns into the same projected line. The ruled-table candidates are then rejected for text overhang, and fallback detection produces one merged table. This is a separate line-grouping / table-consumption issue rather than a failure of the geometry-component split itself.

I opened a separate follow-up issue for that downstream behavior: #414. I suggest keeping this PR narrowly scoped to separated ruled grid components. I can rebase this PR onto the current main and narrow it to the side-by-side geometry case if that is still useful.

I have not uploaded the PDF or added it as a repository fixture yet. I can provide the self-authored, generic fixture if you would like to inspect it.

@Chengyunlai

Copy link
Copy Markdown
Author

Update: the synthetic reproduction PDF is now available here:

It is a self-authored Word-to-PDF document containing two independent side-by-side ruled tables with shared row coordinates. PR #392 separates their geometry components; the remaining downstream projected-line issue and its tested fix are documented in #414.

@Chengyunlai
Chengyunlai force-pushed the codex/fix-separated-grid-components branch from 514a2ef to 9d740a4 Compare August 13, 2026 09:23
@Chengyunlai Chengyunlai changed the title fix: keep separated ruled grids in distinct components fix: keep side-by-side ruled grids separate Aug 13, 2026
@Chengyunlai

Copy link
Copy Markdown
Author

Rebased onto the latest main and narrowed this PR as proposed. It now changes only horizontal-segment clustering for the side-by-side/shared-row case; the vertical clustering change and stacked-table regression covered by #394 have been removed. The downstream projected-line behavior remains separate in #414.

@logan-markewich

Copy link
Copy Markdown
Contributor

This PR doesn't fix the file attached in the Issue comment

@Chengyunlai Chengyunlai changed the title fix: keep side-by-side ruled grids separate fix: keep side-by-side ruled tables separate Aug 15, 2026
@Chengyunlai

Copy link
Copy Markdown
Author

Thanks for calling this out — you were correct that the previous PR head did
not fix the file linked in the issue comment.

I reproduced the public CLI failure again at the exact previous head
(9d740a4) and updated the causal model. There were two separate stages in the
same user-visible failure:

  1. the horizontal rules were merged across the whitespace gutter;
  2. after those grids were separated, projection still grouped same-y text from
    both table rectangles into shared lines, so ruled-table consumption rejected
    them and fallback merged the output again.

The PR now includes the second-stage fix at 26b79a6. On the same published
PDF and the same command:

lit parse /input.pdf --no-ocr --format markdown --output /results/output.md --quiet

the output now has two independent headings and two independent 3-column
Markdown tables. I updated the PR description with the public PDF and hash,
the exact before/after outputs, the two-stage root cause, regression coverage,
and validation results.

I also tested an adjacent smaller shape rather than assuming it was covered.
Its tables are now correctly separate, but same-y sibling headings can still
be mistaken for one wrapped heading. That is a different downstream
heading-classification invariant, with its own public fixture and regression
constraints, so I opened #418 instead of widening this patch further.

Would you be willing to re-review the updated PR against the published PDF?

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.

Side-by-side ruled tables still share projected text lines

2 participants