diff --git a/crates/typst-layout/src/rules.rs b/crates/typst-layout/src/rules.rs index 8bcd6654..52ef7442 100644 --- a/crates/typst-layout/src/rules.rs +++ b/crates/typst-layout/src/rules.rs @@ -10,11 +10,11 @@ use typst_library::foundations::{ }; use typst_library::introspection::{Counter, Locator, LocatorLink}; use typst_library::layout::{ - Abs, AlignElem, Alignment, Axes, BlockBody, BlockElem, ColumnsElem, Em, GridCell, - GridChild, GridElem, GridItem, HAlignment, HElem, HideElem, InlineElem, LayoutElem, - Length, MoveElem, OuterVAlignment, PadElem, PlaceElem, PlacementScope, Region, Rel, - RepeatElem, RotateElem, ScaleElem, Sides, Size, Sizing, SkewElem, Spacing, - StackChild, StackElem, TrackSizings, VElem, + Abs, AlignElem, Alignment, Axes, BlockBody, BlockElem, ColumnsElem, Em, + FixedAlignment, GridCell, GridChild, GridElem, GridItem, HAlignment, HElem, HideElem, + InlineElem, LayoutElem, Length, MoveElem, OuterVAlignment, PadElem, PlaceElem, + PlacementScope, Region, Rel, RepeatElem, RotateElem, ScaleElem, Sides, Size, Sizing, + SkewElem, Spacing, StackChild, StackElem, TrackSizings, VElem, }; use typst_library::math::EquationElem; use typst_library::model::{ @@ -240,8 +240,9 @@ const HEADING_RULE: ShowFn = |elem, engine, styles| { let numbering = Counter::of(HeadingElem::ELEM) .display_at_loc(engine, location, styles, numbering)? .spanned(span); + let align = styles.resolve(AlignElem::alignment); - if hanging_indent.is_auto() { + if hanging_indent.is_auto() && align.x == FixedAlignment::Start { let pod = Region::new(Axes::splat(Abs::inf()), Axes::splat(false)); // We don't have a locator for the numbering here, so we just diff --git a/crates/typst-library/src/model/heading.rs b/crates/typst-library/src/model/heading.rs index d61aa415..3e8677a1 100644 --- a/crates/typst-library/src/model/heading.rs +++ b/crates/typst-library/src/model/heading.rs @@ -177,12 +177,16 @@ pub struct HeadingElem { /// The indent all but the first line of a heading should have. /// - /// The default value of `{auto}` indicates that the subsequent heading - /// lines will be indented based on the width of the numbering. + /// The default value of `{auto}` uses the width of the numbering as indent + /// if the heading is aligned at the [start]($direction.start) of the [text + /// direction]($text.dir), and no indent for center and other alignments. /// /// ```example /// #set heading(numbering: "1.") - /// #heading[A very, very, very, very, very, very long heading] + /// = A very, very, very, very, very, very long heading + /// + /// #show heading: set align(center) + /// == A very long heading\ with center alignment /// ``` #[default(Smart::Auto)] pub hanging_indent: Smart, diff --git a/tests/ref/heading-hanging-indent-auto-center-align.png b/tests/ref/heading-hanging-indent-auto-center-align.png new file mode 100644 index 00000000..086f2eea Binary files /dev/null and b/tests/ref/heading-hanging-indent-auto-center-align.png differ diff --git a/tests/suite/model/heading.typ b/tests/suite/model/heading.typ index 4e04e5c5..e8d96727 100644 --- a/tests/suite/model/heading.typ +++ b/tests/suite/model/heading.typ @@ -101,6 +101,11 @@ comment spans lines #set heading(numbering: "1.1.a.") = State of the Art +--- heading-hanging-indent-auto-center-align --- +#set heading(numbering: "1.1.a.") +#show heading: set align(center) += Center aligned + --- heading-hanging-indent-zero --- #set heading(numbering: "1.1.a.", hanging-indent: 0pt) = State of the Art