How to avoid horizontal stacks shifting margins?

I am not certain whether it is intended or a bug, but, when using stack with a horizontal direction, max width is calculated for each element independently, resulting in a shifted right page margin.

E.g. the following code

this is a #h(1fr) normal paragraph
#stack(dir: ltr, "(1) ", [this is a #h(1fr) stack])

results in the following placing:

The right margin of the stack is shifted to the right by the width of (1) . (should be noted that this is not fr-specific and affects line breaking as well)

If this is indeed intended, my question is, what, if not stack, should be used for creation of e.g. custom list-like layouts?

Hello. Please read How to post in the Questions category before posting a question (from the pinned topic).

1 Like

Hmm, I think it is a bug, since by default everything must follow the set margins. You should open an issue about it.

It depends on how your list layout supposed to work. Internally, lists are implemented through grid. typst/crates/typst-layout/src/lists.rs at ad539ef4ed0551a7eb22f7c9c0ab1c0fd1b59209 · typst/typst · GitHub


Thank you! Grids do seem more suitable, and avoid the bug.

I’ll file an issue right away.

1 Like

Also relevant, this Discord discussion:

It’s definitely still an issue, but I’d just prefer grid out of principle. I’m not aware of something that can be done with a stack, but not a grid.