Skip to content

Spacing between list elements only works for top sublist element #5510

Closed

Description

@DTAG-lnu

Description

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:
Skärmbild från 2024-11-25 15-21-48

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.

Reproduction URL

https://typst.app/project/rxAaN1fm8jJuAmo80Adcwm

Operating system

Web app, Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Dec 3, 2024
  2. added
    layout
    on Dec 5, 2024
  3. laurmaedje commented on Dec 5, 2024

    @laurmaedje
    Member

    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:

    if self.tight(styles) {
    let leading = ParElem::leading_in(styles);
    let spacing =
    VElem::new(leading.into()).with_weak(true).with_attach(true).pack();
    realized = spacing + realized;
    }

    Maybe it should attach with list spacing instead. (The default spacing for tight lists is leading anyway.)

  4. DTAG-lnu commented on Dec 9, 2024

    @DTAG-lnu
    Author

    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.

  5. xkevio commented on Dec 9, 2024

    @xkevio
    SponsorContributor

    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:

    if self.tight(styles) {
    let leading = ParElem::leading_in(styles);
    let spacing =
    VElem::new(leading.into()).with_weak(true).with_attach(true).pack();
    realized = spacing + realized;
    }

    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.

    #set par(spacing: 0.65em)
    #set list(spacing: 1em)
    
    - Linked Lists
    
      - Classes
    
      - Methods
    
      - Different Variants

    image

  6. laurmaedje commented on Dec 9, 2024

    @laurmaedje
    Member

    This is closely related but slightly different. Here, the block above & below spacing of lists is not affected by list.spacing.

  7. xkevio commented on Dec 9, 2024

    @xkevio
    SponsorContributor

    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.

  8. saecki commented on May 5, 2025

    @saecki
    Member

    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:

    Image

    I think the expected result would be to use list spacing if available, and then fall back to using paragraph (leading|spacing).

  9. laurmaedje commented on May 5, 2025

    @laurmaedje
    Member

    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:

    #set par(leading: 0em)
    #set list(spacing: 4em)
    #show list: set block(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. 
    Image

    The list above/spacing applies to both tight and non-tight list, but the attach spacing generated for tight lists overrides it.

  10. saecki commented on May 5, 2025

    @saecki
    Member

    Oh, I see. So for non-tight lists the list spacing should be ignored?

  11. laurmaedje commented on May 5, 2025

    @laurmaedje
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions