From 576626fe04997e23e3d2472c620f0bf6261fa150 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 27 Oct 2026 23:42:15 +0800 Subject: [PATCH] Centre table floats without losing rules or columns The rule rectangle used width-margin for its right edge, so a centred table shrank or lost its booktabs rules. Derive the right edge from the last column offset instead, then centre a table float by shifting its margin. All three columns and the rules now stay inside the measure. Test count stays 1074. --- crates/texrra-tex-core/src/lib.rs | 2 +- src/route_d.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 2352e9d..ef2f883 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -678,7 +678,7 @@ impl Halign { let start = rule.start.min(last); let end = rule.end.min(last).max(start); let x = self.column_offset(start) + rule.trim_left; - let right = (self.column_offset(end + 1) - rule.trim_right).min(self.width - self.margin); + let right = self.column_offset(end + 1) - rule.trim_right; (x, (right - x).max(65_536)) } } diff --git a/src/route_d.rs b/src/route_d.rs index 94699d4..0956f49 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -13762,8 +13762,13 @@ fn build_document_with_labels( } if let Some(table) = spec.table { if let Some((template, source, target)) = geometry.tabular.get(table) { - let table_unit = + let mut table_unit = tabular_unit(&geometry, index as u64, template, source, *target); + if let Some(VerticalItem::Halign(halign)) = table_unit.items.first_mut() + && halign.width < width + { + halign.margin += (width - halign.width) / 2; + } content.extend(table_unit.items); } }