为 Pylatex 部分设置不同的边距

为 Pylatex 部分设置不同的边距

我想为 Pylatex 文档的不同部分设置不同的边距(包括标题、部分和小节)。我是 Latex 新手

我目前正在使用这个最小示例按如下方式设置几何选项。我尝试通过设置几何选项来更改后续部分的边距,但没有成功:

from pylatex import Command, Document, Section

geometry_options = {"tmargin": "0.5in", "lmargin": "0in", "bmargin": "0.5in", "rmargin": "0in"}
doc = Document(geometry_options=geometry_options, fontenc='T1')

with doc.create(Section('Section1')) as Sect1:
    Sect1.append('some text')

with doc.create(Section('Section2')) as Sect2:
    Sect2.append('some more text')
    Sect2.geometry_options = Command({'margins':'1in'})

doc.generate_pdf("testoutput", clean_tex=False)

这是相应的乳胶输出:

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[tmargin=0.5in,lmargin=0in,bmargin=0.5in,rmargin=0in]{geometry}%
%
%
%
\begin{document}%
\normalsize%
\section{Section1}%
\label{sec:Section1}%
some text

%
\section{Section2}%
\label{sec:Section2}%
some more text

%
\end{document}

如何在 Pylatex 代码中更改文档内的边距?

答案1

你希望 pylatex 翻译

Sect2.geometry_options = Command({'margins':'1in'})

类似于

\newgeometry{margins=1in}

但是 pylatex 可能不懂几何学。

阅读几何手册(cmd:)texdoc geometry,用户界面部分。可能\savegeometry\loadgeometry会成为你的朋友,如果您可以将必要的命令从 pylatex 文件传递​​到 LaTeX。我不知道该怎么做,但从您的代码来看,您似乎知道这些事情。

相关内容