3 回答

TA貢獻1859條經驗 獲得超6個贊
這是搜索如何在 ReportLab 中制作嵌套列表的人們的最佳結果,
您可以將ListFlowable
alist
作為其項目之一。如果其中list
包含 aParagraph
和 another ,它將在同一個項目符號點內ListFlowable
呈現嵌套ListFlowable
在 the 之后的Paragraph
權利。
t = ListFlowable(
? ? [
? ? ? ? Paragraph("Item no. 1", style),
? ? ? ? [
? ? ? ? ? ? Paragraph("Item no. 2", style),
? ? ? ? ? ? ListFlowable(
? ? ? ? ? ? ? ? [
? ? ? ? ? ? ? ? ? ? Paragraph("sublist item 1", style),
? ? ? ? ? ? ? ? ? ? ListItem(Paragraph('sublist item 2', style), bulletColor='red')
? ? ? ? ? ? ? ? ],
? ? ? ? ? ? ? ? bulletType='bullet',
? ? ? ? ? ? ? ? bulletFontSize=5,
? ? ? ? ? ? ? ? start='square',
? ? ? ? ? ? )
? ? ? ? ],
? ? ? ? Paragraph("Item no. 3", style),
? ? ],
? ? bulletType='1',
? ? bulletFormat='%s.',
? ? bulletFontSize=8,
)
不要費心隱藏多余的項目符號,或告訴 ReportLab 不要渲染它然后必須仔細管理value后續的ListItem項目符號。<ul>它與 HTML 中的s 和s完全一樣<ol>。
上面的代碼呈現如下:

TA貢獻1816條經驗 獲得超6個贊
您可以通過將嵌套列表插入 ListItem 并將值參數設置為 0 來關閉一個列表項的編號:ListFlowable([ Paragraph(...), ListItem(ListFlowable(...nested list...), value= 0) ListItem(Paragraph(...), value=2) # 讓列表繼續下去 ])

TA貢獻1898條經驗 獲得超8個贊
所以我現在想出解決這個問題的方法是將它再次嵌套在另一個 ListFlowable 中,并將 leftIndent 設置為“0”,將 bulletColor 設置為“white”。
lf = ListFlowable([
ListFlowable([
ListItem(Paragraph(text1, styles["Normal"]), spaceAfter=12),
ListFlowable([ListItem(Paragraph(text1a, styles["Normal"])),
ListItem(Paragraph(text1b, styles["Normal"])),t
], bulletType='bullet', bulletFontSize= 5, bulletOffsetY= -2, leftIndent=10, start='circle')], bulletColor='white', leftIndent=0),
ListItem(Paragraph(text2, styles["Normal"]), spaceBefore=12),
], bulletType='1', bulletFontSize= 10)
添加回答
舉報