Stretch tabular* tables to their target width

This commit is contained in:
gloamxun committed 2026-10-26 20:36:49 +08:00
1 parent 3770de0804
commit 80a5e8272d
3 files changed
+41 -2

No files matched your search

+39
View File
@@ -2931,6 +2931,22 @@ fn tabular_unit(
if let Some(VerticalItem::Halign(halign)) = unit.items.first_mut() {
halign.margin = separator;
halign.width += 2 * separator;
if let Some(target) = target
&& halign.column_widths.len() > 1
&& halign.width < target
{
let extra = target - halign.width;
if halign.column_skips.is_empty() {
halign.width = target;
} else {
let gaps = halign.column_skips.len() as i64;
let per = extra / gaps.max(1);
for skip in &mut halign.column_skips {
*skip += per;
}
halign.width += per * gaps;
}
}
}
unit
}
@@ -12376,6 +12392,29 @@ See \ref{fig:a} and \ref{tab:b}.";
assert!(!json.contains("#1"));
}
#[test]
fn tabular_star_stretches_to_its_width() {
let source = "\\begin{tabular*}{200pt}{ll}\na & b \\\\\n\\end{tabular*}";
let (body, geometry) = geometry_and_body(source);
let blocks = paragraphs(&body).expect("paragraphs");
let document = build_document(&blocks, &geometry);
let halign = document
.units
.iter()
.flat_map(|unit| &unit.items)
.find_map(|item| match item {
VerticalItem::Halign(halign) => Some(halign),
_ => None,
})
.expect("tabular halign");
assert_eq!(halign.column_widths.len(), 2);
assert!(
(halign.width - 200 * SCALE).abs() < 2 * SCALE,
"width {}",
halign.width
);
}
#[test]
fn tabular_star_renders_its_table() {
let source = "\\begin{tabular*}{200pt}{ll}\na & b \\\\\n\\end{tabular*}";