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.

1 Like

Yeah, I’ve switched to a grid already and it’s working great, thank you

Which leads me to a question: why is stack a thing anyway, given there is grid?

(sorry if it’s not ok to bump a closed topic)

It’s just a small follow-up, so not too bad imo.

I assume just history. At some point the two functions were considered to be solutions for different use cases (and the defaults of the two may still support that view), but once grid became the “dominant” tool for this kind of task, development of stack stalled. Since you have to actively spend effort to remove something (not just the code, deprecation first and then updating the docs) it just didn’t happen yet.

1 Like