簡體   English   中英

如何在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源,但在那里找不到太多。 這是我所擁有的:

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)

此代碼導致: 不需要

但我希望它看起來像: 期望的

我手動編輯了第二張圖像以獲得所需的效果。

我曾考慮過在列表中創建一個列表,以獲取縮進的項目符號,但后來我不知道如何使文本更靠近項目符號。

只需將leftIndent參數傳遞到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
)

編輯:您必須設置leftIndentListFlowable來定義項目符號和文本之間的空間。

我最終對其進行了進一步的研究( ReportLab源代碼… ),以發現如何處理未垂直正確對齊的項目符號。 我建議以下附加kwargs其他項目符號列表控制狂:

  • bulletOffsetY + ve向上移動,-ve向下移動
  • bulletFontSize如果您像我一樣默認情況下以大項目符號結尾
  • spaceBeforespaceAfter控制列表項之間的垂直間距

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM