如何将整个表与Python Reportlab库对齐?

如何将整个表与Python Reportlab库对齐?,python,report,centering,reportlab,Python,Report,Centering,Reportlab,使用reportlab 3.1.44,我试图将表格向左对齐(页面上的整个表格,而不是单元格)。 这是我的密码: from reportlab.platypus import SimpleDocTemplate from reportlab.platypus.tables import Table, TableStyle from reportlab.lib import colors from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA

使用reportlab 3.1.44,我试图将表格向左对齐(页面上的整个表格,而不是单元格)。 这是我的密码:

from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.tables import Table, TableStyle 
from reportlab.lib import colors 
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT

doc = SimpleDocTemplate('sample2.pdf', showBoundary=1) 
t = Table(
    (('','North','South','East','West'), 
    ('Quarter 1',100,200,300,400), 
    ('Quarter 2',100,400,600,800), 
    ('Total',300,600,900,'1,200')),

    (72,36,36,36,36), 
    (24,16,16,18)
) 

t.setStyle( 
    TableStyle([ 
        ('HALIGN',(0,0),(-1,-1),'LEFT'),\
        ('GRID', (0,0), (-1,-1), 0.25, colors.red, None, (2,2,1)), 
        ('BOX', (0,0), (-1,-1), 0.25, colors.blue), 
    ]) 
)
t.alignment = TA_LEFT
story = [t] 
doc.build(story) 

它仍然与中心对齐。有没有办法解决这个问题?

显然,表样式方法不起作用。 以下是我如何让它工作的:

t = Table((('','North','South','East','West'), 
('Quarter 1',100,200,300,400), 
('Quarter 2',100,400,600,800), 
('Total',300,600,900,'1,200')), 
(72,36,36,36,36), 
(24, 16,16,18) 
,hAlign='LEFT')

同时
t.hAlign='LEFT'
而不是
t.alignment=TA_LEFT
。几乎和你写的一样