Skip to content

List and enum markers are not aligned with the baseline of the item's contents #1204

Closed

Description

@andreasKroepelin

Description

For a bullet list item with extra line height, the bullet point is not aligned with the text as one would expect for "usual" items.

- abc
- def #box(stroke: 1pt, inset: 3mm, baseline: 3mm)[test]
- #lorem(30)

produces:
image

As the third bullet point shows, the issue is not the total height of the item but really its line height.

Reproduction URL

No response

Operating system

Web app

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on May 14, 2023
  2. added
    layout
    on May 20, 2023
  3. N3xed commented on Jun 23, 2023

    @N3xed

    Ran into this as well.

    It is somewhat workaroundable with a bullet list, by e.g.:

    #set list(marker: (level) => {
        align(horizon, sym.bullet)
    })

    But this will even center the bullet between multiple lines. Meaning, if there is a list item containing two lines of text, the bullet will be centered vertically in front of those two lines.

    The same problem exists with enum, but there (to my knowledge) is no such hack, since I can't access the counter that is counting the enumeration. If someone knows how to do this, that would be appreciated. Also note, that #set enum(number-align: horizon) is disallowed for some reason.

    A fix to this would also be very appreciated. (Also, loving typst so far).

  4. changed the title [-]Bullet point is not aligned with text at beginning of list item[/-] [+]List and enum markers are not aligned with text at beginning of item[/+] on Apr 1, 2024
  5. changed the title [-]List and enum markers are not aligned with text at beginning of item[/-] [+]List and enum markers are not aligned with the baseline of the item's contents[/+] on Apr 8, 2024
  6. StrangeGirlMurph commented on Apr 24, 2024

    @StrangeGirlMurph

    Just for anyone who found this issue and is looking for a workaround. Someone smart on the Discord Server came up with this:

    #show list.item: it => context [
      #let marker = list.marker.at(0)
      #let height = measure[#it.body].height
      #box(height: height)[#marker #it.body] \
    ]
    
    - Something in the list
    
    - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$
    
    - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$
    

    image

  7. Enter-tainer commented on Jun 4, 2024

    @Enter-tainer
    Contributor

    I wonder if it will help if we don't use a grid when layouting enum/list/term. See LaTeX's enumitem's method:

    https://www.texnia.com/archive/enumitem.pdf

    image

  8. crimestop commented on Jun 6, 2024

    @crimestop

    Just for anyone who found this issue and is looking for a workaround. Someone smart on the Discord Server came up with this:

    #show list.item: it => context [
      #let marker = list.marker.at(0)
      #let height = measure[#it.body].height
      #box(height: height)[#marker #it.body] \
    ]
    
    - Something in the list
    
    - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$
    
    - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$
    

    image

    For list with multi-line item, we should use the following code instead to get the correct height

    #show list.item: it => context [
      #let marker = list.marker.at(0)
      #layout(size => [
        #let (height,) = measure(
          block(width: size.width, it.body),
        )
        #box(height: height)[#marker #it.body] \
      ])
    ]
    
  9. Enter-tainer commented on Jun 6, 2024

    @Enter-tainer
    Contributor

    Kind reminder: all code posted aboved breaks nested list items. Like:

    - a
    - b
      - c
      - d
    - e
  10. crimestop commented on Jun 16, 2024

    @crimestop

    Kind reminder: all code posted aboved breaks nested list items. Like:

    - a
    - b
      - c
      - d
    - e

    You may try this

      #let indent_level = state("indent_level", -1)
      #let sign = it =>{
        if it > 0{
          1
        }else if it == 0{
          0
        }else{
          -1
        }
      }
      #show list: it => context [
        #indent_level.update(it => it + 1)
        #for item in it.children [
          #if item.body.func() == list [
            #item.body
          ] else [
            #context pad(left:sign(indent_level.get()) * 1em)[#layout(size => [
              #let (height,) = measure(
                block(width: size.width, item.body),
              )
              #box(height: height)[ #list.marker.at(calc.rem(indent_level.get(), list.marker.len())) #item.body] 
            ])]
          ]
        ]
        #indent_level.update(it => it - 1)
      ]
    

    Cannot do the same for enum because I seem to have no access to the function apply_kth that appears in the source code of enum

  11. Enter-tainer commented on Jun 16, 2024

    @Enter-tainer
    Contributor

    I think it would make sense if we change how list is layouted within typst.

  12. Enter-tainer commented on Jun 16, 2024

    @Enter-tainer
    Contributor

    see also #4126

  13. scrouthtv commented on Jul 22, 2024

    @scrouthtv

    Regarding @crimestop 's proposed solution, I'd suggest fixing the box's width to 100% in order to fix items with centered content, such as equation:

      #let indent_level = state("indent_level", -1)
      #let sign = it =>{
        if it > 0{
          1
        }else if it == 0{
          0
        }else{
          -1
        }
      }
      #show list: it => context [
        #indent_level.update(it => it + 1)
        #for item in it.children [
          #if item.body.func() == list [
            #item.body
          ] else [
            #context pad(left:sign(indent_level.get()) * 1em)[#layout(size => [
              #let (height,) = measure(
                block(width: size.width, item.body),
              )
              #box(height: height)[ #list.marker.at(calc.rem(indent_level.get(), list.marker.len())) #item.body] 
            ])]
          ]
        ]
        #indent_level.update(it => it - 1)
      ]

    Example:

    - Bernoulli-Gleichung für kompressible Gase:
      $ c_1^2/2 + kappa/(kappa - 1) p_1/rho_1 = dots $

    image

  14. OrangeX4 commented on Aug 24, 2024

    @OrangeX4

    I have a new way to solve this problem. I replaced list with terms, which solved the hanging-indent issue.

    #show list.item: it => {
      let current-marker = if type(list.marker) == array {
        list.marker.at(0)
      } else {
        list.marker
      }
      let hanging-indent = measure(current-marker).width + .6em + .3pt
      set terms(hanging-indent: hanging-indent)
      if type(list.marker) == array {
        terms.item(
          current-marker,
          {
            // set the value of list.marker in a loop
            set list(marker: list.marker.slice(1) + (list.marker.at(0),))
            it.body
          },
        )
      } else {
        terms.item(current-marker, it.body)
      }
    }

    Example:

    - #lorem(15)
      - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$
        - Basis of $C(A)$ : $vec(1,0,0),vec(5,-1,-1)$

    image

  15. laurmaedje commented on Aug 24, 2024

    @laurmaedje
    Member

    Yeah, it's planned to change the internal implementation so something similar (though of course not using terms), possibly via #4541, maybe through another PR.

  16. 1 remaining item

  17. Fr4nk1inCs commented on Oct 30, 2024

    @Fr4nk1inCs

    To adjust to the new behaviors of list's spacing, and the context expression part:

    • Lists:
      #show list.item: it => {
        // The generated terms is not tight
        // So setting `par.spacing` is to set the result lists' spacing
        let spacing = if list.spacing != auto {
          enum.spacing
        } else if enum.tight {
          par.leading
        } else {
          par.spacing
        }
        set par(spacing: spacing)
      
        let current-marker = if type(list.marker) == array {
          list.marker.at(0)
        } else {
          list.marker
        }
      
        context {
          let hanging-indent = measure(current-marker).width + terms
            .separator
            .amount
          set terms(hanging-indent: hanging-indent)
          if type(list.marker) == array {
            terms.item(
              current-marker,
              {
                // set the value of list.marker in a loop
                set list(marker: list.marker.slice(1) + (list.marker.at(0),))
                it.body
              },
            )
          } else {
            terms.item(current-marker, it.body)
          }
        }
      }
    • Enums:
      #let counting-symbols = "1aAiI一壹あいアイא가ㄱ*"
      #let consume-regex = regex("[^" + counting-symbols + "]*[" + counting-symbols + "][^" + counting-symbols + "]*")
      
      #show enum.item: it => {
        if it.number == none {
          return it
        }
        // The generated terms is not tight
        // So setting `par.spacing` is to set the result enums' spacing
        let spacing = if enum.spacing != auto {
          enum.spacing
        } else if enum.tight {
          par.leading
        } else {
          par.spacing
        }
        set par(spacing: spacing)
      
      
        let new-numbering = if type(enum.numbering) == function or enum.full {
          numbering.with(enum.numbering, it.number)
        } else {
          enum.numbering.trim(consume-regex, at: start, repeat: false)
        }
        let current-number = numbering(enum.numbering, it.number)
        context {
          let hanging-indent = measure(current-number).width + terms
            .separator
            .amount
      
          set terms(hanging-indent: hanging-indent)
      
          terms.item(
            strong(delta: -300, numbering(enum.numbering, it.number)),
            {
              if new-numbering != "" {
                set enum(numbering: new-numbering)
                it.body
              } else {
                it.body
              }
            },
          )
        }
      }
  18. CreadorSW commented on Mar 4, 2025

    @CreadorSW

    I just encounter myself with this issue right now. As a simple Typst user is kinda weird for me to see that this issue was not addressed from day 1. So much time has passed since its opening. It is hard to believe that is not solved yet. I hope the team can fix it in a native way. I don't want to come back to Latex but this must be solved in order to keep the dignity lol.

  19. HPDell commented on May 1, 2025

    @HPDell

    Hi,

    I encountered this issues yesterday. Finally, I rewrite the way list and enum showing like this:

    #let mod(x, y) = {
      if x < y {
        x
      } else {
        int(calc.round(calc.fract(x / y) * y))
      }
    }
    
    #let enumitem(
      marker: (sym.circle.filled, sym.triangle.r.filled, sym.dash),
      numberer: ("1)", "a)", "i)"),
      children
    ) = {
      let item-template(
        label-width: 1em,
        label-sep: 4pt,
        hanging: 1em,
        alignment: left,
        label: [],
        body: []
      ) = block(
        inset: (left: hanging),
        above: .6em,
        {
          set par(first-line-indent: (amount: 0em, all: true), hanging-indent: 0em)
          box(
            width: 0em,
            move(box(
              width: label-width,
              inset: (right: label-sep),
              align(alignment, label)
            ), dx: -label-width)
          )
          body
        }
      )
      let queue = ((
        marker: none,
        body: []
      ),)
      let cur = (0,)
      let cur-max = (children.len(),)
      let cur-number = ()
      let cur-type = ()
      let cur-marker = 0
      let cur-numberer = 0
      let depth = 0
      let doc = []
      let elem = children
      let elem-last = none
      while cur.at(0) < cur-max.at(0) {
        if cur.at(depth) >= cur-max.at(depth) {
          let qe = queue.pop()
          queue.last().body += item-template(..qe)
          let _ = cur.pop()
          let _ = cur-max.pop()
          if cur-type.len() > 0 {
            let _ = cur-type.pop()
          }
          depth -= 1
          cur.last() += 1
          continue
        }
        // Deep-first search current element
        let c = 0
        elem = children
        while c <= depth {
          elem = if type(elem) == array {
            elem.at(cur.at(c))
          } else if elem.func() == list.item {
            elem.body.children.at(cur.at(c))
          } else if elem.func() == enum.item {
            elem.body.children.at(cur.at(c))
          } else {
            elem
          }
          c += 1
        }
        if elem.func() == list.item {
          if cur-number.len() <= depth {
            cur-number.push(none)
          }
          // Find marker
          if cur-type.len() == 0 {
            cur-type.push("list")
          } else if cur-type.len() <= depth {
            cur-type.push("list")
            if cur-type.at(depth - 1) == "enum" {
              cur-marker = 0
            } else {
              cur-marker = mod(cur-marker + 1, marker.len())
            }
          }
          let label = marker.at(cur-marker)
          if "children" in elem.body.fields() {
            queue.push((
              label: label,
              label-width: 1em,
              body: []
            ))
            depth += 1
            cur.push(0)
            cur-max.push(elem.body.children.len())
          } else {
            queue.push((
              label: label,
              label-width: 1em,
              body: elem.body
            ))
            cur.at(depth) += 1
            let qe = queue.pop()
            queue.last().body += item-template(..qe)
          }
        } else if elem.func() == enum.item {
          if cur-type.len() == 0 {
            cur-type.push("enum")
          } else if cur-type.len() <= depth {
            cur-type.push("enum")
            if cur-type.at(depth - 1) == "list" {
              cur-numberer = 0
            } else {
              cur-numberer = mod(cur-numberer + 1, numberer.len())
            }
          }
          if cur-number.len() <= depth {
            cur-number.push(1)
          } else if cur-number.at(depth) == none {
            cur-number.at(depth) = 1
          }
          let number = cur-number.at(depth)
          cur-number.at(depth) += 1
          let label = numbering(numberer.at(cur-numberer), number)
          if "children" in elem.body.fields() {
            queue.push((
              label: label,
              label-width: 2em,
              alignment: right,
              body: []
            ))
            depth += 1
            cur.push(0)
            cur-max.push(elem.body.children.len())
          } else {
            queue.push((
              label: label,
              label-width: 2em,
              alignment: right,
              body: elem.body
            ))
            cur.at(depth) += 1
            let qe = queue.pop()
            queue.last().body += item-template(..qe)
          }
        } else {
          queue.last().body += elem
          cur.at(depth) += 1
        }
        elem-last = elem
      }
      queue.pop().body
    }

    The function is tested by

    #show list: body => {
      show: block.with(above: 1em, below: 1em, inset: (left: 2em))
      set par(spacing: .6em)
      enumitem(body.children)
    }
    
    #show enum: body => {
      show: block.with(above: 1em, below: 1em, inset: (left: 2em))
      set par(spacing: .6em)
      enumitem(body.children)
    }
    
    = Item list
    
    - Bullet1
    - Bullet2
      - Bullet2.1
      - Bullet2.2 with math equation $A = mat(a_1,a_2;a_3,a_4;a_5,a_6)$
      - Bullet2.3
        - Bullet2.3.1
        - 符号项目2.3.2
        - Bullet2.3.3
          - Bullet2.3.3.1
          - Bullet2.3.3.1
          Continuous...
    
    = Numbered list
    
    + Numered1
    + Numered2
      + Numered2.1
      + Numered2.2
      + Numered2.3
        + Numered2.3.1
        + Numered2.3.2
        + Numered2.3.3
          + Numered2.3.3.1
          + Numered2.3.3.1
    
    = Mixed List
    
    + Item1
    + Item2
      - Item2.1
      - Item2.2
      - Item2.3
        - Item2.3.1
        - Item2.3.2
        - Item2.3.3
          + Item2.3.3.1
          + Item2.3.3.2
            + Item2.3.3.2.1

    And the output

    Image

    However, the code is messy and some features, like indent, body indent, and rtl text, are not supported. I wish the official group can release their own improved implementation soon,

  20. pacaunt commented on May 26, 2025

    @pacaunt

    Another alternatives for workarounds: This one also handle hanging indent, numbering with full enumeration and support native typst syntax.

    #show list: it => context {
      for child in it.children {
      let width = measure(it.marker.at(0)).width + it.indent + it.body-indent
      let spacing = if it.tight { par.leading } else { par.spacing }
      let inset = if text.dir == rtl { (right: width) } else { (left: width) }
      set list(marker: it.marker.slice(1) + (it.marker.at(0),))
      block(inset: inset, below: spacing, above: spacing)[
        #h(-width)
        #box(it.marker.at(0), width: width)#child.body
      ]
    }
      
    } 
    
    #show enum: it => context {
      let new-children = ()
      let curr = 0
      let curr-level = state("_enum",())
      let spacing = if it.tight { par.leading } else { par.spacing }
    
      for i in range(it.children.len()) {
        let child = it.children.at(i)
        if child.has("number") {
          new-children.push((number: curr-level.get() + (child.number,), body: child.body))
          curr = child.number
        } else {
          curr += 1
          new-children.push((number: curr-level.get() + (curr,), body: child.body))
        }
      }
    
      let max-width = calc.max(..new-children.map(child => measure(numbering(it.numbering, ..child.number)).width))
      let width = max-width + it.indent + it.body-indent
      let inset = if text.dir == rtl { (right: width) } else { (left: width) }
      for child in new-children {
        if it.full { curr-level.update(n => child.number) } 
        block(inset: inset, below: spacing, above: spacing)[
          #h(-width)
          #box(align(right,numbering(it.numbering, ..child.number)), width: width - it.body-indent)#h(it.body-indent)#child.body
        ]
      }
      curr-level.update(())
    }
  21. pravinbansal-pt commented on Jul 6, 2025

    @pravinbansal-pt

    @pacaunt your solution for enum causes a dx in the label, which is correct with the following

    #show enum: it => context {
      let new-children = ()
      let curr = 0
      let curr-level = state("_enum",())
      let spacing = if it.tight { par.leading } else { par.spacing }
    
      for i in range(it.children.len()) {
        let child = it.children.at(i)
        if child.has("number") {
          new-children.push((number: curr-level.get() + (child.number,), body: child.body))
          curr = child.number
        } else {
          curr += 1
          new-children.push((number: curr-level.get() + (curr,), body: child.body))
        }
      }
    
      let max-width = calc.max(..new-children.map(child => measure(numbering(it.numbering, ..child.number)).width))
      let width = max-width + it.indent + it.body-indent
      let inset = if text.dir == rtl { (right: width) } else { (left: width) }
      for child in new-children {
        if it.full { curr-level.update(n => child.number) } 
        block(inset: inset, below: spacing, above: spacing)[
          #h(-width)
          #box(numbering(it.numbering, ..child.number), width: it.indent + max-width)#h(it.body-indent)#child.body
        ]
      }
      curr-level.update(())
    }
  22. pravinbansal-pt commented on Jul 11, 2025

    @pravinbansal-pt

    Problem with above method is that it will force the list into blocks, which must start on a new line and cannot (to my knowledge) be embedded inline, so running lists are not possible,

    They should take the above form, but take the below form:

    1. x
    1. x
    1. 
      1. y
    
    #h(1cm)
    
    #show enum: it => context {
      let new-children = ()
      let curr = 0
      let curr-level = state("_enum",())
      let spacing = if it.tight { par.leading } else { par.spacing }
    
      for i in range(it.children.len()) {
        let child = it.children.at(i)
        if child.has("number") {
          new-children.push((number: curr-level.get() + (child.number,), body: child.body))
          curr = child.number
        } else {
          curr += 1
          new-children.push((number: curr-level.get() + (curr,), body: child.body))
        }
      }
    
      let max-width = calc.max(..new-children.map(child => measure(numbering(it.numbering, ..child.number)).width))
      let width = max-width + it.indent + it.body-indent
      let inset = if text.dir == rtl { (right: width) } else { (left: width) }
      for child in new-children {
        if it.full { curr-level.update(n => child.number) } 
        block(inset: inset, below: spacing, above: spacing)[
          #h(-width)
          #box(numbering(it.numbering, ..child.number), width: it.indent + max-width)#h(it.body-indent)#child.body
        ]
      }
      curr-level.update(())
    }
    
    1. x
    1. x
    1. 
      1. y
    Image

    Hopefully something @reknih is at least aware of!

  23. tianyi-smile commented on Jul 31, 2025

    @tianyi-smile

    As a temporary solution, the package itemize can now be used.

    #import "@preview/itemize:0.2.0" as el
    #show: el.default-enum-list

    For example:

    Image
    The source code is as follows:
    #set page(height: auto, margin: 35pt)
    #let item-test = [
      + one $vec(1, 1, 1)$
        $
          x^2 + y^2 = z^2
        $
      + #rect(height: 2em, width: 2em) #lorem(2)
      + #block(stroke: 1pt)[two $vec(1, 1, 1,)$]
      + $ (a + b)^2 = a^2 + 2a b + b^2 $
      + + #lorem(2)
      + - #lorem(2)
        - #lorem(2)
    ]
    #table(
      columns: (1fr, 1fr),
      [native], [itemize],
      [
        #item-test
      ],
      [
        #show: el.default-enum-list
        #item-test
      ],
    )
  24. flokl commented on Aug 25, 2025

    @flokl

    Because it wasn't mentioned yet, also lists that break over a page inside a table with align horizon are affected in v0.13.1.

    #set page(paper: "a6")
    
    #lorem(130)
    #table(
      align: horizon,
      [+ #lorem(20)]
    )
    
  25. linked a pull request that will close this issueImproved list layout #7895on May 27, 2026
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