diff --git a/crates/typst-layout/src/grid/layouter.rs b/crates/typst-layout/src/grid/layouter.rs index 08c44f3a2..20766bb38 100644 --- a/crates/typst-layout/src/grid/layouter.rs +++ b/crates/typst-layout/src/grid/layouter.rs @@ -1447,7 +1447,7 @@ impl<'a> GridLayouter<'a> { .as_ref() .and_then(Repeatable::as_repeated) .is_none_or(|footer| footer.start != last_header_end) - && self.lrows.last().is_some_and(|row| row.index() < last_header_end) + && self.lrows.len() == self.current_header_rows && !in_last_with_offset( self.regions, // Since we're trying to find a region where to place all diff --git a/crates/typst-layout/src/grid/repeated.rs b/crates/typst-layout/src/grid/repeated.rs index 264210a75..33534e0f2 100644 --- a/crates/typst-layout/src/grid/repeated.rs +++ b/crates/typst-layout/src/grid/repeated.rs @@ -373,6 +373,7 @@ impl<'a> GridLayouter<'a> { } if let HeadersToLayout::NewHeaders { headers, short_lived } = headers { + let placing_at_the_start = skipped_region || self.lrows.is_empty(); for header in headers { let header_height = self.layout_header_rows(header.unwrap(), engine, disambiguator)?; @@ -391,6 +392,11 @@ impl<'a> GridLayouter<'a> { } } } + + if placing_at_the_start { + // Track header rows at the start of the region. + self.current_header_rows = self.lrows.len(); + } } Ok(())