Skip to content

Support for dynamic page margins #1483

Open

Description

@michel-steuwer

Description

While the header and footer can depend on the page size using the locate function, this does not seem the case for page margin.

#1308 adds support for inside and outside margins, but I am also interested in influencing the size of header and footer, particularly for a title page.

Feature request:

  • add an API that allows to set the margin of the page depending on the page number
  • alternatively, support a dedicated margin setting for the title page

Use Case

I am trying to create a template mimicking the ACM acmart latex class: https://github.com/michel-steuwer/typst-acmart/tree/main

The first page has an extra long footer compared to all other pages: https://github.com/michel-steuwer/typst-acmart/blob/main/sample-acmsmall.pdf

I currently don't know how to build this with Typst.

Activity

  1. laurmaedje commented on Jun 13, 2023

    @laurmaedje
    Member

    For the title page, you can simply do #page(margin: ..)[Title page contents] independently from other page set rules. In general, you can change any page setting at any point, but it will force a pagebreak. What you propose would still be useful if margins should change for one continous flow of content. I plan to support that too at some point, but it's difficult to implement.

  2. michel-steuwer commented on Jun 13, 2023

    @michel-steuwer
    Author

    but it will force a pagebreak

    And that's why I can't do it. The content is supposed to flow over from the first page.

    After looking at the current code for a bit, I understand that this is not a straightforward change, as the changes of the margins impact the number of pages required.

  3. michel-steuwer commented on Aug 8, 2023

    @michel-steuwer
    Author

    I have an additional use case of a letter where the first page has different information in the margins (such as the senders address) than the rest of the letter. Again, the content should seamlessly flow across all pages.

  4. laurmaedje commented on Aug 8, 2023

    @laurmaedje
    Member

    Does the sender address need to be part of the header? Can't it be in the main flow?

  5. michel-steuwer commented on Aug 8, 2023

    @michel-steuwer
    Author

    That's not the point.

    I currently don't know how to type set a letter that would satisfy the corporate design guidelines of my University.

    page1
    page2

  6. laurmaedje commented on Aug 8, 2023

    @laurmaedje
    Member

    I see, you want the right margin to change while keeping a single flow. That's unfortunately not yet possible because of a fundamental limitation in paragraph layout. I do wonder if/how you would achieve this in LaTeX since it also has some limitations related to paragraphs of changing width (because of the justification algorithm). That said, I do want to support this down the road.

  7. added
    layout
    and removed on Nov 24, 2023
  8. changed the title [-]Support for page margins to depend on page number[/-] [+]Support for dynamic page margins[/+] on Feb 28, 2024
  9. jbdyn commented on Sep 23, 2025

    @jbdyn

    In the meantime, I managed to realize @michel-steuwer's letter template: I used the base margins defined on the second page. To get the extra margins for the first page, I used meander's text threading capabilities and placed the side panel and the expanded footer as obstacles.

  10. claell commented on May 10, 2026

    @claell

    Adding another data point for the same underlying requirement, from formal/business/legal letter templates.

    This overlaps strongly with the university/corporate-design letter example above. A common professional letter layout needs:

    • Page 1 to reserve a right-side information rail for sender/contact/reference metadata.
    • The main text on page 1 to be narrower because of that rail.
    • Continuation pages to use a wider text area, often with only a compact running header/footer.
    • The body text to remain one continuous flow, with normal automatic page breaking.

    Manually splitting the source into "first page body" and "continuation body" is not a good fit for this use case because small edits can move the page break, especially in legal or administrative correspondence.

    The meander workaround mentioned above sounds promising, but it would still be very useful to have a native way to express this kind of first-page layout difference without giving up automatic flow.

    Small clarification: I do not know of another robust way to implement this layout in Typst today while keeping the document as one continuous text flow. If there is already a Typst-native pattern for this that does not require manual page splitting, I would be very interested in learning about it. From what I can tell, though, this issue is what currently blocks this formal-letter use case.

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

    feature requestlayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions