I can’t seem to find a way to achieve consistent spacing with bullet lists and numbered lists. The spacing of the marked spots is somehow tied to par(leading)? What should I change to achieve same spacing throughout my list without affecting the par line spacing?
Maybe you could try something like this,
#show list: set par(leading: välys)
#show list.item: set par(leading: 0.2em)
So inside the list set par.leading and then restore it in list.item so that any paragraphs in the list still use your tight spacing
Thank you bluss. I adjusted my code but still can’t quite get the consistency with spacings with all the items:
Any ideas how to continue?
Here’s the typst code from the pic in plain text:
#set page(paper: "a5")
#let välys = 2.2em
#let linespace = 0.2em
#set list(
marker: (
text(1.0em, fill: rgb("#0969DA"),[▸]),
text(1.0em, fill: rgb("#0969DA"),[▹]),
)
)
#set enum(
numbering: (it => text(1.0em, fill: rgb("#0969DA"),strong[#it.]))
)
#show enum: set par(leading: välys, spacing: välys)
#show list: set par(leading: välys, spacing: välys)
#set par(leading: linespace, spacing: välys)
#show list.item: set par(leading: linespace)
#show enum.item: set par(leading: linespace)
#lorem(20)
#lorem(20)
- #lorem(20)
- #strong[Aaa] #lorem(20)
- #strong[Bbb] #lorem(20)
- #strong[Ccc] #lorem(20)
- #strong[Ddd] #lorem(20)
- #strong[Eee] #lorem(20)
- #strong[Fff] #lorem(20)
- #strong[Ggg] #lorem(20)
1. #strong[Hhh] #lorem(20)
2. #strong[Iii] #lorem(20)
3. #strong[Jjj] #lorem(20)
1. #strong[Kkk] #lorem(20)
- #strong[Lll] #lorem(20)
- #strong[Mmm] #lorem(20)
- #strong[Nnn] #lorem(20)
That looks inconsistent yes, first problem is on the item called Ccc I assume. I don’t have any suggestion.
Exactly.
Thanks for taking a look.
I’ll keep this unsolved for the time being.
@Jarko, please read How to post in the Questions category.
When creating a topic in Questions, there should be no reason to post an image of the code the question is about, instead it needs to be included using instructions from the linked post above. If you need to show an output, then it must be inserted by itself without unnecessary information like source code.
Sometimes it’s also useful to add details
block or “Hide Details” from the post composer dropdown menu with the gear icon.
[details="Summary"]
This text will be hidden
[/details]
Or the HTML tag:
<details><summary>Summary</summary>
Big image or code block
```typ
```
</details>
It is not clear what exact spacing and in what places you want, and the provided snippet looks wrong, because it looks like it tries to override the same field in different places.
Here is a solution where everything is using the same spacing (or so it looks visually):
#set page(width: 150mm, height: auto)
#let marker-num-color = rgb("#0969DA")
#set list(marker: ([▸], [▹]).map(text.with(marker-num-color)))
#set enum(numbering: (..n) => text(marker-num-color, numbering("1.", ..n)))
#let spacing = 2.2em
#set par(spacing: spacing, leading: spacing, justify: true)
#let words = 26
#lorem(words)
#lorem(words)
- #lorem(words)
- #strong[Aaa] #lorem(words)
- #strong[Bbb] #lorem(words)
- #strong[Ccc] #lorem(words)
- #strong[Ddd] #lorem(words)
- #strong[Eee] #lorem(words)
- #strong[Fff] #lorem(words)
- #strong[Ggg] #lorem(words)
+ #strong[Hhh] #lorem(words)
+ #strong[Iii] #lorem(words)
+ #strong[Jjj] #lorem(words)
+ #strong[Kkk] #lorem(words)
- #strong[Lll] #lorem(words)
- #strong[Mmm] #lorem(words)
- #strong[Nnn] #lorem(words)
If you want to set in-paragraph line spacing separately, but the rest is the same, then use this:
#set par(spacing: 2.2em, leading: 0.2em, justify: true)
#show selector.or(list.item, enum.item): block
I’m not sure why v(0pt)
works but ""
doesn’t. This post is actually a duplicate of How to control spacing between an outer enum and inner bullet list, but with some additional settings on top, which makes the solution a bit different.
You solved it. Thank you so much.
Thank you.
This could be the default placeholder text for us newbies posting a new topic.
Nice. What insight led you to this solution? This inserts an extra space so that something about paragraph placement or spacing logic changes, is that it?
As I said, it felt, and it mostly is a duplicate of How to control spacing between an outer enum and inner bullet list, so I just yonked How to control spacing between an outer enum and inner bullet list - #3 by Andrew and adapted it. It was too much, but then I reduced it to 0, and it looked correct, so I rolled with it. I’m definitely not sure how the logic works with this one, but the rest of the solution does make sense for the most part.
When you select something, you should use “Quote” or “Copy Quote”. Doesn’t look like you did, because that is not how I wrote it. Also, there is a Discource bug that the language identifier is not preserved when quoting, so you kind of have to re-insert it yourself for the time being.
I think all answers so far are missing something:
- The spacing between the list and the preceding paragraph is given by
par.leading
if the list istight
and attached (i.e. no empty line in between), andblock.spacing
(which falls back topar.spacing
) otherwise. - The spacing between two list items is given by
list.spacing
, which by default (i.e. when set toauto
) falls back topar.leading
orpar.spacing
, depending on whether the list istight
or not.
This means that just with the syntax you use to create the list, you can already control much of the spacing.
Tight and attached | Tight and not attached | Not tight and attached | Not tight and not attached |
---|---|---|---|
|
|
|
|
|
|
|
|
Usually, you only need to add the empty line once to mark the whole list as not tight. For example, the list
- First item
- Second item
- Third item
will not be tight, even though there is no empty line between the last two items. However, when creating sub-lists, a new nested list is created, which may attach to the body of the parent list item. For example, in
- First item
- Second item
- Nested list
the nested sub-list is tight and attached to paragraph containing the text “Parent list item”, even though the outer list is not tight. To fix that, you would need to make the nested list again not attached or not tight by adding another empty line.
If you don’t want to always have to introduce empty lines, you can override the spacing rules introduced by the tightness and paragraph attachments by just wrapping every list item (and enum item, maybe also terms item) in a block with custom set spacing. If you still want set rules for list.spacing
to have an effect, you can use that as the block spacing:
// If `list.spacing` is set to auto, falls back to `par.spacing`.
#show list.item: it => block(spacing: list.spacing, it)
#show enum.item: it => block(spacing: enum.spacing, it)
// Alternatively, if you don't need list.spacing rules to work:
#show selector.or(list.item, enum.item): block
The spacing between list items and the spacing between the preceding paragraph and the list is then only determined by that value, making all lists behave the same, no matter if you put any empty lines in your source code.
Thank you for the elaborate explanation. I’ve simplified my answer.
Thank you guys.
To demonstrate and for debugging purposes I added: #show selector(par): rect
The typst code is now very close to what I am really trying to achieve: I do need to add additional spacing between the “top level” paragraphs which do not have list or enum markers before them. The ideal situation would be to have control over these “real non-enum non-list paragraphs” whether they are followed by an enum-list-item or something else (such as another “real paragraph” or heading or image or table or quote). But I struggle to select them as can be seen from the screenshot below:
Here’s the typst code that’s being used so far:
#set page(width: 150mm, height: auto)
#let marker-num-color = rgb("#0969DA")
#set list(marker: ([▸], [▹]).map(text.with(marker-num-color)))
#set enum(numbering: (..n) => text(marker-num-color, numbering("1.", ..n)))
#let välys = 1.2em
#let riviväli = 0.2em
#set par(spacing: välys, leading: riviväli, justify: true)
#show selector.or(list.item, enum.item): block
#show selector(par): rect // How to adjust this line?
#let words = 26
#lorem(words)
#lorem(words)
- #lorem(words)
- #strong[Aaa] #lorem(words)
- #strong[Bbb] #lorem(words)
- #strong[Ccc] #lorem(words)
- #strong[Ddd] #lorem(words)
- #strong[Eee] #lorem(words)
- #strong[Fff] #lorem(words)
- #strong[Ggg] #lorem(words)
+ #strong[Hhh] #lorem(words)
+ #strong[Iii] #lorem(words)
+ #strong[Jjj] #lorem(words)
+ #strong[Kkk] #lorem(words)
- #strong[Lll] #lorem(words)
- #strong[Mmm] #lorem(words)
- #strong[Nnn] #lorem(words)
If you have further questions or problems, feel free to open a new Questions topic, since this question has been answered.