如何让项目符号直接出现在 Python 的 reportlab 包中缩进列表的文本旁边? [英] How can I make the bullet appear directly next to the text of an indented list in the reportlab package for python?
问题描述
我正在使用 reportlab 2.6 的 ListFlowable 制作带有彩色圆圈项目符号的项目符号列表.但是,我希望项目符号出现在文本旁边,而不是与前面的非缩进文本对齐.我试图打开 ListFlowable 源代码,但在那里找不到太多内容.这是我所拥有的:
I'm using reportlab 2.6's ListFlowable to make a bulleted list with colored circle bullets. However, I would like the bullet to appear next to the text, rather than aligned with the preceding, non-indented text. I tried to open up the ListFlowable source, but I couldn't find much there. Here's what I have:
from reportlab.platypus import Paragraph, ListFlowable, ListItem, SimpleDocTemplate, Frame
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.colors import CMYKColor
doc = SimpleDocTemplate("SOtest.pdf")
styles = getSampleStyleSheet()
Story = []
Story.append(Paragraph("Header Text, I dont want the bullets directly below the H"
,styles['Normal']))
my_list = ListFlowable(
[
ListItem(Paragraph("Line 1",styles['Normal'])
,bulletColor = CMYKColor(0.81, 0.45, 0.53, 0.23)
,value = 'circle'
),
ListItem(Paragraph("Line 2",styles['Normal'])
,bulletColor = CMYKColor(0.81, 0.45, 0.53, 0.23)
,value = 'circle'
)
],
bulletType='bullet',
start='circle'
)
Story.append(my_list)
doc.build(Story)
这段代码的结果是:
但我希望它看起来像:
我手动编辑了第二张图片以获得所需的效果.
I manually edited the second image to get the desired effect.
我想在列表中创建一个列表,以获得一个缩进的项目符号,但后来我不知道如何使文本更接近项目符号.
I thought about making a list inside a list, to get an indented bullet, but then I wouldn't know how to dedent the text closer to the bullet.
推荐答案
只需将 leftIndent
参数传递到 ListItem
中即可.
Just pass a leftIndent
parameter into the ListItem
.
my_list = ListFlowable([
ListItem(Paragraph("Line 1", styles['Normal']),
leftIndent=35, value='circle',
bulletColor=CMYKColor(0.81, 0.45, 0.53, 0.23)
),
ListItem(Paragraph("Line 2", styles['Normal']),
leftIndent=35, value='circle',
bulletColor=CMYKColor(0.81, 0.45, 0.53, 0.23))
],
bulletType='bullet',
start='circle',
leftIndent=10
)
您必须设置 ListFlowable
的 leftIndent
来定义项目符号和文本之间的空间.
You have to set the leftIndent
of the ListFlowable
for defining the space between the bullets and the text.
这篇关于如何让项目符号直接出现在 Python 的 reportlab 包中缩进列表的文本旁边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!