Fix auto hanging-indent for centered headings (#6839)

This commit is contained in:
Philipp Niedermayer 2025-09-01 11:20:42 +02:00 committed by GitHub
parent 1f41a9f2a1
commit 3d64f7b659
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 9 deletions

View File

@ -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<HeadingElem> = |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

View File

@ -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<Length>,

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

View File

@ -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