From d248a847644d6b00e1934bd5c0d87b82695745b5 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 01:30:22 +0800 Subject: [PATCH] Keep tables that fit on a single page intact --- src/rust_typeset/pdf/layout.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index f2b06a1..d650ac3 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -3016,6 +3016,16 @@ pub(super) fn build_positioned_pages( continue; } + // Keep a table that fits on one page intact instead of + // splitting its rows at the bottom of the current page. + if table_height > 0 && total_height <= page_goal.saturating_sub(top_skip) { + let page_nonempty = pages.last().is_some_and(|page| !page.items.is_empty()); + if page_nonempty && cursor.saturating_add(total_height) > page_goal { + pages.push(PositionedPage::default()); + cursor = top_skip; + } + } + let mut line_index = 0; let mut has_caption_lines = false; for line in caption_lines {