You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spacing between list elements only works for top sublist element #5510
I am working with Touying to make lecture slides, but I believe this to be a general problem with lists. I have posted the problem in the forum and user miles-1 also agrees that this might be a problem in Typst. The problem is that when I set the spacing for lists with the following code:
#set list( spacing: 1.2em, )
It only applies the spacing, as it seems, to the first subitem. The rest of them are spaced out with a larger (default) spacing. This can be seen in this image:
I have set up an example in the reproduction URL where I also, with the help of user miles-1, done an example at the end where the position of the spacing is shown to be put differently by using the code below:
#show list.item: it => { show [ ].func(): [SPACE IN LIST HERE] it }
He, and I think so too, believe that this shows the unexpected behaviour as the text "SPACE IN LIST HERE" is clearly in different places.
I hope this is something that someone can continue to work on or explain if it is the intended behaviour.
If there is no blank line between text and a list item of a tight list, it attaches to the paragraph with normal line spacing (aka leading). The relevant code is here:
Yes, I believe you are right. Though I am not in a position to be able to offer any additional code for doing that, so I will have to see if anyone picks it up.
If there is no blank line between text and a list item of a tight list, it attaches to the paragraph with normal line spacing (aka leading). The relevant code is here:
Maybe it should attach with list spacing instead. (The default spacing for tight lists is leading anyway.)
I don't think it only affects tight lists (though that should also be fixed), it "correctly" uses paragraph spacing here for a non-tight list, even though list spacing is explicitly set.
This is closely related but slightly different. Here, the block above & below spacing of lists is not affected by list.spacing.
Ah I see, similarly, this shouldn't be too hard to fix. Seems like just an oversight from all the block layouting reworks and such though I don't exactly know where that would be.
This is closely related but slightly different. Here, the block above & below spacing of lists is not affected by list.spacing.
That's actually not true, as can be seen in this example, the spacing above nested lists (green lines) uses paragraph (leading|spacing), but below (red lines) the list spacing is used:
I think the expected result would be to use list spacing if available, and then fall back to using paragraph (leading|spacing).
That's actually not true, as can be seen in this example, the spacing above nested lists (green lines) uses paragraph (leading|spacing), but below (red lines) the list spacing is used:
I think where the red lines are, you're observing list spacing from the outer list. See this example:
#setpar(leading: 0em)
#setlist(spacing: 4em)
#showlist: setblock(above: 1em, below: 2em)
- Linked lists
- Classes // 0em attach leading above here because it's a tight list
- Methods
- Different variants // 4em list spacing below this item// -- list spacing from the outer list
- Testing
- Unit test // 1em list above spacing here because it's not tight
- Setting up
- Examples // only 2em spacing below here// --- the list below's below spacing
No big gap.
To summarize the current state, just to clarify things in my head:
List spacing is between items
Above/below is around the list except above tight lists, where we always have leading
The issue here is that list spacing differs from leading and hence the list looks untidy. Wide lists also exhibit this behaviour, but it's easy to fix by also setting above/below spacing. Meanwhile, tight lists will always use leading. This is undesirable in some scenarios, but in principle makes sense if you view the tight list as becoming part of the paragraph (see also #3206). If we don't want to use leading, the question is whether list spacing or above spacing is more apprioriate. We could also potentially adjust the above/below spacing of tight lists with a built-in show set rule.
I'm not sure right now what the correct design is. I would need to think more about this.
Activity
laurmaedje commentedon Dec 5, 2024
If there is no blank line between text and a list item of a tight list, it attaches to the paragraph with normal line spacing (aka leading). The relevant code is here:
typst/crates/typst-library/src/model/list.rs
Lines 161 to 166 in 4f3ba7f
Maybe it should attach with list spacing instead. (The default spacing for tight lists is leading anyway.)
DTAG-lnu commentedon Dec 9, 2024
Yes, I believe you are right. Though I am not in a position to be able to offer any additional code for doing that, so I will have to see if anyone picks it up.
xkevio commentedon Dec 9, 2024
I don't think it only affects tight lists (though that should also be fixed), it "correctly" uses paragraph spacing here for a non-tight list, even though list
spacingis explicitly set.laurmaedje commentedon Dec 9, 2024
This is closely related but slightly different. Here, the block above & below spacing of lists is not affected by list.spacing.
xkevio commentedon Dec 9, 2024
Ah I see, similarly, this shouldn't be too hard to fix. Seems like just an oversight from all the block layouting reworks and such though I don't exactly know where that would be.
saecki commentedon May 5, 2025
That's actually not true, as can be seen in this example, the spacing above nested lists (green lines) uses paragraph (leading|spacing), but below (red lines) the list spacing is used:
I think the expected result would be to use list spacing if available, and then fall back to using paragraph (leading|spacing).
laurmaedje commentedon May 5, 2025
I think where the red lines are, you're observing list spacing from the outer list. See this example:
The list above/spacing applies to both tight and non-tight list, but the attach spacing generated for tight lists overrides it.
saecki commentedon May 5, 2025
Oh, I see. So for non-tight lists the list spacing should be ignored?
laurmaedje commentedon May 5, 2025
To summarize the current state, just to clarify things in my head:
The issue here is that list spacing differs from leading and hence the list looks untidy. Wide lists also exhibit this behaviour, but it's easy to fix by also setting above/below spacing. Meanwhile, tight lists will always use leading. This is undesirable in some scenarios, but in principle makes sense if you view the tight list as becoming part of the paragraph (see also #3206). If we don't want to use leading, the question is whether list spacing or above spacing is more apprioriate. We could also potentially adjust the above/below spacing of tight lists with a built-in show set rule.
I'm not sure right now what the correct design is. I would need to think more about this.