我正在使用 python-docx
在 python
中创建一个 Word .docx
并且我想设置 inside
和 outside
边距以及 gutter
。如何做到这一点?
给定一个部分
,我可以像这样设置左右边距:
section.top_margin = Mm(6.6)
section.bottom_margin = Mm(6.6)
但是内部和外部如何设置呢?
最佳答案
你可以这样尝试:
from docx import Document
from docx.shared import Mm
# Create a new Document
doc = Document()
# Add a section to the document
section = doc.sections[0]
# Set the top, bottom, left, and right margins
section.top_margin = Mm(6.6)
section.bottom_margin = Mm(6.6)
section.left_margin = Mm(6.6)
section.right_margin = Mm(6.6)
# Set the inside and outside margins
section.inside_margin = Mm(12.7) # Inside margin (towards the binding)
section.outside_margin = Mm(12.7) # Outside margin (away from the binding)
# Set the gutter margin (gap between the inside margins of facing pages)
section.gutter = Mm(6.6)
# Save the document
doc.save("your_document.docx")
我通过访问 section.top_margin、section.bottom_margin、section.left_margin 调整了上、下、左、右页边距和 section.right_margin 属性,分别。为了配置内部和外部边距,我使用了 section.inside_margin 和 section.outside_margin 属性。最后,我利用 section.gutter 属性指定了装订线边距。
关于python - 如何设置内边距和外边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77142499/