Skip to content

Custom margins change to default ones #111

Done

Description

@cvas22

Copied from python-docx-template issue 542, opened by @klalex on 2024-05-04.


I set custom margins for page layout in a template. When I generate docx it changes to default one. What I've noticed is that it depends on content. When I remove some content it works properly. If add content back there is issue described.

I use this version:

docxtpl = "^0.17.0"

Activity

  1. added
    bug
    on Nov 9, 2026
  2. cvas22 commented on Nov 22, 2026

    @cvas22
    OwnerAuthor

    @klalex I can't reproduce this on current main, custom page size, orientation and margins survive a render in my tests. Could you attach a template (and the context) where the margins reset? Since it depends on the content, the exact file would help a lot.

  3. cvas22 commented on Nov 25, 2026

    @cvas22
    OwnerAuthor

    @klalex found it, I think. When the paragraph that ends a section also holds a {%p %} tag, the section break got removed with it, so that section picked up the next section's margins. That's why it depended on the content. Fixed in #204, it'll be in the next release, or try pip install git+https://github.com/cvas22/docform. If your template still resets the margins, attach it and I'll reopen.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions