Skip to content

Paragraph justification sometimes doesn't use the full page width #5472

Open

Description

@Andrew15-5

Description

#set page(margin: (left: 3cm, right: 1cm))
#set text(14pt)
#set par(justify: true)

+ Методология и технология проектирования информационных систем: учебное пособие
  \/ Ю. М. Казаков, А. А. Тищенко, А. А. Кузьменко [и др.]. --- Москва: ФЛИНТА,
  \2018. --- 136 с. --- ISBN 978-5-9765-4013-2. --- Текст: электронный \//
  Электронно-библиотечная система «Лань»: [сайт]. --- URL:
  https://e.lanbook.com/book/113460
+ Ипатова, Э. Р. Методологии и технологии системного проектирования информационных
  систем: учебное пособие / Э. Р. Ипатова. --- 2-е изд., стер. --- Москва: ФЛИНТА,
  \2016. --- 256 с. --- ISBN 978-5-89349-978-0. --- Текст: электронный \//
  Электронно-библиотечная система «Лань»: [сайт]. --- URL:
  https://e.lanbook.com/book/84356
// + #lorem(24)

#v(0cm)

+ https://geekbrains.ru/posts/development_methodology_msf --- Методология MSF
+ http://www.informicus.ru/default.aspx?SECTION=6&id=73&subdivisionid=7 --- Методология
  RUP

image

As soon as I insert + #lorem(24) in the first list, they both become full-width:

image

I cannot explain why would this ever happen. I never noticed this before, but apparently this behavior is the same for previous versions too. I guess I rarely have 2 lists on the same page.

By definition, the justification stretches the content to the full-width of the page. My only hunch is something to do with non-Latin/Unicode stuff.

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Nov 26, 2024
  2. Enivex commented on Nov 26, 2024

    @Enivex
    Collaborator

    I suspect that this may be a duplicate of #5449 ? The issues seem very similar

  3. Andrew15-5 commented on Nov 26, 2024

    @Andrew15-5
    ContributorAuthor

    It's not a regression, so I doubt that.

  4. laurmaedje commented on Nov 26, 2024

    @laurmaedje
    Member

    Probably the list (which is laid out as a grid) has shrink-to-fit semantics from the grid.

  5. added
    layout
    on Nov 26, 2024
  6. Andrew15-5 commented on Nov 26, 2024

    @Andrew15-5
    ContributorAuthor

    But I don't know any field that does that, which means there is no workaround? Without completely rewriting the list show rule in Typst.

    https://typst.app/docs/reference/layout/grid/

  7. PgBiel commented on Nov 26, 2024

    @PgBiel
    Contributor

    In principle they are just auto columns, separate lists are separate grids so they aren't in the same column. The underlying problem has the same cause as the centering equations in lists issue (#529).

    However, what isn't clear is why justification isn't requesting the full width. Usually, the text would cause the list to resize to full width due to being too long.

    In either case, the fix would be similar as the other issue. You can try to add #h(1fr) at the end of a line in the smaller list (or in both).

  8. Andrew15-5 commented on Nov 26, 2024

    @Andrew15-5
    ContributorAuthor

    Nice! Adding #h(1fr) at the end of the 1st or 2nd item does the trick, thanks.
    But now I have a small question: how to avoid the space before # (if it actually affects anything)? Because without it, the URL will have the id h(1fr) (which is an interesting edge case for URL + code mode).

  9. PgBiel commented on Nov 26, 2024

    @PgBiel
    Contributor

    I'm pretty sure the space there doesn't make much of a difference since what comes after it is also a space, but, if it's really necessary, you can write #[https://...]#h(1fr).

  10. laurmaedje commented on Nov 27, 2024

    @laurmaedje
    Member

    However, what isn't clear is why justification isn't requesting the full width. Usually, the text would cause the list to resize to full width due to being too long.

    The width is determined as the maximum natural line width after line breaking. So it doesn't necessarily request the full width.

  11. Enivex commented on Nov 27, 2024

    @Enivex
    Collaborator

    However, what isn't clear is why justification isn't requesting the full width. Usually, the text would cause the list to resize to full width due to being too long.

    The width is determined as the maximum natural line width after line breaking. So it doesn't necessarily request the full width.

    That's unfortunate, since it'll lead to situations like this, where the margin is uneven

    Edit: As far as I can recall, this is not how justification works elsewhere

  12. laurmaedje commented on Nov 27, 2024

    @laurmaedje
    Member

    It's only in blocks with shrink-to-fit behaviour.

  13. Enivex commented on Nov 27, 2024

    @Enivex
    Collaborator

    It's only in blocks with shrink-to-fit behaviour.

    How do I know if a given block has that kind of behavior?

    See also #5479

  14. laurmaedje commented on Nov 27, 2024

    @laurmaedje
    Member

    All non-fixed-size blocks have that.

  15. sonovice commented on Jan 24, 2025

    @sonovice

    Just ran into the same issue with figure captions. Here's a reference to a solution that worked in my case if other people stumble upon this issue here the same way I did: #1498 (comment)

  16. pollomarzo commented on Feb 21, 2025

    @pollomarzo

    Ended up here while using a grid layout with an auto column:

    grid(
      columns: (35%, auto),
      column-gutter: 5pt,
      { text("left side")},
      {box(<text>, stroke:(right:black))}
    )

    Image

    (The typo "afull" maximizes the effect, but it is present anyway)
    Can confirm, a bit unintuitive since it depends on the way text wraps within the available space. Since, differently from list, I have control over the grid, explicitly setting both column sizes or placing the text inside a width: 100% box fixes it.

    I too would not have expected the justify to change the column size, but I can see why it would happen

  17. laurmaedje commented on Feb 21, 2025

    @laurmaedje
    Member

    For a grid specifically, it's best to not create a box or block at all and instead use grid.cell:

    #grid(
      columns: (35%, auto),
      column-gutter: 5pt,
      [left side],
      grid.cell(stroke: (right: black))[some text here"],
    )
  18. Gravitonic commented on Mar 7, 2025

    @Gravitonic

    I ran into this issue with some long headings. A simple reproduction:

    #set par(justify: true)
    #set page(margin: (x: 2in))
    
    === #lorem(15)
    
    #lorem(35)
    
    === #lorem(20)
    
    #lorem(35)

    The increased margins make the effect clearer but it seems to be present even with default margins/a wider text area generally.

  19. eltos commented on Mar 17, 2025

    @eltos
    Contributor

    Ended up here trying to justify figure captions as explained in this post in the typst forum. This used to work in typst 0.12, but is broken since typst 0.13.

    typst 0.12 typst 0.13
    Image Image
    #set page(width: 250pt, height: auto, margin: 10pt)
    
    #let caption = "This is an example caption which is veeeeeeeeeeery long"
    
    Default, no justification:
    #show figure.caption: it => {
      set align(left)
      box(width: 230pt, fill: yellow, it) // see https://forum.typst.app/t//1714/4
    }
    #figure(none, caption: caption)
    
    With justification in typst #sys.version:
    #show figure.caption: set par(justify: true)
    #figure(none, caption: caption)

    EDIT: Interestingly, it can be worked around by replacing it (the caption) inside the box with the plain content context[#it.supplement #it.counter.display()#it.separator#it.body]

  20. Andrew15-5 commented on Mar 17, 2025

    @Andrew15-5
    ContributorAuthor

    I literally hit the same issue yesterday. And I wasn't able to make the caption stretch, even with #h(1fr). I assume it's a different bug.

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