How to change font size depending on sublist depth?

I’m currently building a template for touying presentations. For that template I’d like to vary the text size of lists depending on the sublist depth. So for example:

- This text should be 14pt
  - This text should be 12pt
  - This text should be 12pt
- This text should be 14pt

I’ve already tried

#show list.where(depth: 1): set text(size: 12pt)

but while this instruction compiles without error, it does not seem to have any effect on the appearance of my list.

How can I achieve lists that have different font sizes depending on the sublist level?

1 Like

There is also list.item for styling the actual items of the list. However, it wouldn’t help you in this case, because level-based styled of lists is not supported yet:

Here’s one way to do it:

#let list-counter = counter("list")

#show list: set text(14pt)
#show list: it => {
  list-counter.step()

  context {
    set text(10pt) if list-counter.get().first() == 2
    set text(20pt) if list-counter.get().first() >= 3
    it
  }
  list-counter.update(i => i - 1)
}

- A bit larger
  - smol
  - smol
    - well this is large!
- A bit larger
  - smol

set text(10pt) if list-counter.get().first() == 2

Wait this is valid syntax? @PgBiel Is there a difference to

if list-counter.get().first() == 2 { set text(10pt) }

?

Without that syntax, due to rules being scoped, you’d have to write

if condition {
  set something
  it
} else {
  it
}

rather than the shorter

set something if condition
it

It’s possible there will be further ways to avoid that problem in the future, but this is what we have for now.

1 Like