0.12.0 problem on heading spacing

Hi,
with version 0.11.1 i was using this code:

set heading(
  numbering: (..nums) => {
    let vals = nums.pos()
    if vals.len() == 1 {
      return str(vals.first()) + "."
    }
    else if vals.len() <=4 {
      let color = main-color
      if vals.len() == 4 {
        color = black
      }
      return place(dx:-4.5cm, box(width: 4cm, align(right, text(fill: color)[#nums.pos().map(str).join(".")])))
    }
  }
);

To get this result:

image

After updating to 0.12.0, I got this little space before the heading title and I’m not able to change it.

image

Can you give me an help? Thanks a lot.

There indeed seems to be an issue with the interaction between the heading’s hanging-indent and the weak spacing that is placed between the numbering and the body of the heading. When setting the hanging indent to zero, it looks the same as in 0.11.1. I have filed an issue here.

However, the numbering parameter is not really the right place for this kind of styling. For example, look what happens when you try to reference a level-2 heading:

image

A better place way to implement this kind of number layout would be in a show rule for headings. The numbering itself should only represent which kind of numbers should be printed:

#set heading(
  hanging-indent: 0pt,
  numbering: (..nums) => {
    let vals = nums.pos()
    let pattern = if vals.len() == 1 { "1." }
                  else if vals.len() <= 4 { "1.1" }
    if pattern != none { numbering(pattern, ..nums) }
  }
)

For positioning and coloring, you can then write a show rule for headings. I tried my best to mimic the behaviour of your code:

#show heading: it => {
  if it.level == 1 or it.level > 4 {
    return it
  }

  let number = if it.numbering != none {
    set text(fill: main-color) if it.level < 4
    let num = counter(heading).display(it.numbering)
    let width = measure(num).width
    let gap = 5mm
    place(dx: -width - gap, num)
  }
  
  block(number + it.body)
}

When you now try to reference a section, it looks as one would expect:

image

2 Likes

For future referenece, do you mean 0.12?

Yes, sorry. I will correct it.

Thanks a lot. I will change the code with your suggestions!