[reportlab-users] Getting Nested table aligned to top

Mike Driscoll mdriscoll at co.marshall.ia.us
Mon Aug 3 14:53:54 EDT 2009


Hi Robin,

> Mike Driscoll wrote:

>> Hi,

>>

>> It looks like my post got eaten due to my screenshot, so I have

>> uploaded it to flickr:

>> http://www.flickr.com/photos/25220999@N03/3773123700/

>>

>> I am trying to get a set of nested tables to align at the top. There

>> are 6 rows in the screenshot. The first row is 3 "Earnings", the 2nd

>> is the four row table, the 3rd is three "Deductions", the 4th is the

>> 5 row table, etc. Notice that the bottom row has the first two

>> columns lower the the last one. Is there a way to force that row to

>> be aligned at the top? Right now, I use the following code:

>>

>> tblThree = Table(data3, colWidths=colWidths, style=LIST_STYLE,

>> hAlign="LEFT", vAlign="TOP")

>>

>> This does not work. Does anyone have a better idea? I am using Python

>> 2.5 on Windows XP with the latest ReportLab.

>>

>> Thanks,

>>

>> Mike

>

> This single row example shows nested tables aligned right, top.

>

> ###############################################################

> from reportlab.lib import colors

> from reportlab.platypus.doctemplate import SimpleDocTemplate

> def getTable(x=0):

> data=[('','Europe','Asia'),

> ('Quarter 1',100,200),

> ('Quarter 2',100,400),

> ]

> W=[62,26,26]

> H=[24,16,16,18]

> if x:

> data[3:3] = [('Quarter 3',103,404),('Quarter 4',104,396)]

> H[3:3] = [16,16]

> LR = ['Total',300,600]

> for j in xrange(1,len(LR)):

> LR[j] = sum([data[i][j] for i in xrange(1,len(data))])

> data.append(LR)

> return Table(data,W,H,style=TableStyle([('GRID', (0,0), (-1,-1),

> 0.25, colors.black),('FONTSIZE',(0,0),(-1,-1),8)]))

>

> T=Table([[getTable(0),getTable(0),getTable(1)]],

> style=TableStyle([

> ('ALIGN', (0,0), (-1,0), 'RIGHT'),

> ('VALIGN', (0,0), (-1,-1), 'TOP'),

> ('GRID', (0,0), (-1,-1), 0.25, colors.red),

> ]),

> )

> SimpleDocTemplate('tnestt.pdf', showBoundary=1).build([T])

> ###############################################################


That worked quite well. I don't know why setting "valign" didn't, but
I'm glad this worked. Thanks for the example. I had to tweak it a little
as three rows were aligning themselves to the left and one to the right,
but it's much closer to what it should be.

Thanks again,

Mike


More information about the reportlab-users mailing list