diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index 6d1b653f7..271d9467b 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -1344,7 +1344,9 @@ fn finalize( let width = if !region.x.is_finite() || (!expand && lines.iter().all(|line| line.fr().is_zero())) { - p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default() + region + .x + .min(p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default()) } else { region.x }; diff --git a/tests/ref/visualize/shape-rect.png b/tests/ref/visualize/shape-rect.png index 17675400f..48d40447b 100644 Binary files a/tests/ref/visualize/shape-rect.png and b/tests/ref/visualize/shape-rect.png differ diff --git a/tests/typ/visualize/shape-rect.typ b/tests/typ/visualize/shape-rect.typ index 951d5beaa..17dd0f92a 100644 --- a/tests/typ/visualize/shape-rect.typ +++ b/tests/typ/visualize/shape-rect.typ @@ -53,3 +53,11 @@ --- // Error: 15-21 expected length, color, dictionary, stroke, none, or auto, found array #rect(stroke: (1, 2)) + +--- +#set page(width: 17.8cm) +#lorem(100) +#rect(lorem(100)) +#set par(justify: true) +#lorem(100) +#rect(lorem(100))