Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vertically align Paragraphs within a Table using Reportlab?

I'm using Reportlab to generate report cards. The report cards are basically one big Table object. Some of the content in the table cells needs to wrap, specifically titles and comments, and I also need to bold certain elements.

To accomplish both the wrapping and ability to bold, I'm using Paragraph objects within the Table. My table needs several of these elements vertically aligned to 'middle' but the Paragraph alignment and snaps my text to the bottom of the cell.

How can I vertically align my Paragraph within a Table cell?

like image 773
Soviut Avatar asked Dec 17 '22 09:12

Soviut


1 Answers

I have to ask: have you tried the tablestyle VALIGN:MIDDLE?

something like:

t=Table(data) 
t.setStyle(TableStyle([('VALIGN',(-1,-1),(-1,-1),'MIDDLE')])) 

(more details in section 7.2 of the ReportLab user guide)

If that doesn't do it, then your paragraph object must be the full height of the cell, and internally aligned to the bottom.

Could you please post a small sample that reproduces the problem?

like image 120
Jim Carroll Avatar answered Dec 28 '22 08:12

Jim Carroll