2013-02-21 26 views
4

我使用reportlab 2.6的ListFlowable來製作帶有彩色圓圈項目符號的項目符號列表。但是,我希望子彈出現在文本旁邊,而不是與前面的非縮進文本對齊。我試圖打開ListFlowable源,但我找不到那裏。下面是我有:如何使項目符號直接出現在reportlab軟件包for python中縮進列表的文本旁邊?

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) 

該代碼產生這樣的: Not Desired

但我希望它看起來像: Desired

我手動編輯的第二圖像來獲得預期的效果。

我曾想過在列表中想做一個列表,以得到一個縮進的子彈,但後來我不知道如何縮小文本更接近子彈。

回答

3

只需將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 
) 

編輯: 您必須設置ListFlowableleftIndent定義子彈和文本之間的空間。

+0

這使子彈,我想它,但文字也移動之間的垂直間隙。理想情況下,子彈將與「1號線」中的「L」相鄰。 – 2013-02-21 08:52:22

+0

完成編輯。如果我理解你的話,這應該是解決方案。 – floqqi 2013-02-21 09:15:56

+0

太棒了!我實際上是在提問後不久就以另一種方式解決了這個問題(我會稍微公佈這個答案),但我喜歡這個問題 – 2013-02-21 21:04:50

1

我最終進一步研究了它(ReportLab source code…),以發現如何處理子彈未正確對齊的垂直方向。我建議以下的其他項目符號列表控制狂額外kwargs

  • bulletOffsetY +已經上移,-ve往下移動
  • bulletFontSize如果你結束了巨大的子彈在默認情況下,像我一樣
  • spaceBeforespaceAfter控制列表項
+0

儘管這並沒有回答這個問題,但它有助於解決問題我當時就是因此導致我首先閱讀這個問題!希望它也能幫助別人。 – jenniwren 2016-11-16 05:57:40

相關問題