<p>我已经挣扎了几个小时,到今天为止,提供的解决方案对我不起作用。我在<a href="https://www.programcreek.com/python/example/60058/reportlab.lib.styles.ParagraphStyle" rel="nofollow noreferrer">programcreek</a>上发现了另一个,差不多。稍作润色之后,这一个就成功了:</p>
<pre><code>#First you need to instantiate 'getSampleStyleSheet()'
from reportlab.lib.styles import (ParagraphStyle, getSampleStyleSheet)
style = getSampleStyleSheet()
yourStyle = ParagraphStyle('yourtitle',
fontName="Helvetica-Bold",
fontSize=16,
parent=styles['Heading2'],
alignment=1,
spaceAfter=14)
</code></pre>
<p>要使用它,只需像这样调用<em>yourStyle</em>:</p>
<pre><code>Story.append(Paragraph("Whatever printed with yourStyle", yourStyle))
</code></pre>
<p>必须使用文档中所示的数字进行对齐:</p>
<blockquote>
<p>There are four possible values of alignment, defined as constants in the module reportlab.lib.enums. These are TA_LEFT, TA_CENTER or TA_CENTRE, TA_RIGHT and TA_JUSTIFY, with values of 0, 1, 2 and 4 respectively. These do exactly what you would expect.</p>
</blockquote>
<p>我之所以贴出答案,是因为我在任何地方都找不到确切的答案,希望能对其他人有所帮助。</p>