[reportlab-users] changed font size in table

Tom Brown brown at esteem.com
Wed Mar 2 12:00:07 EST 2005


On Wednesday 02 March 2005 02:50, Christoph Zwerschke wrote:
> >> Actually, setting 'VALIGN' to 'BOTTOM' was an attempt to move the text
> >> down in the cells. The text rides high in the cells and setting
> >> 'VALIGN' has no effect. In fact, if I didn't set the rowHeights, the
> >> text would be partially out of the top of each cell.
>
> Tom, I think the problem is that you decreased the FONTSIZE, but not the
> LEADING. So you get 3 points default bottom padding + 12 points default
> text height (leading) which is already at the top of the 15 point cell.
> Try again using a LEADING of 8, this will look better.
>
> There will be still a small problem because a LEADING of 8 will be too
> small for a FONTSIZE of 8. So I recommend setting the LEADING to 11 and
> the TOPADDING and BOTTOMPADDING to 2. This should look nice.
>
> The VALIGN has no effect here because in your example the LEADING and
> the PADDING already sum up to the full row height, so there is no room
> for vertical adjustment anyway.
>
> Please also note that Reportlab had a problem with VALIGN=MIDDLE which
> has been fixed in version 1.20 only.
>
> -- Christoph Zwerschke

Christoph,

Your suggestions fixed the problem. The text is centered perfectly. Here is 
what my code looks like now:

  def getTable(self, data):
    style = [
      ('GRID', (0,0), (-1,-1), 0.5, colors.grey),
      ('FONTSIZE', (0,0), (-1, -1), 8),
      ('LEADING', (0,0), (-1, -1), 11),
      ('TOPPADDING', (0,0), (-1, -1), 2),
      ('BOTTOMPADDING', (0, 0), (-1, -1), 2),
    ]
    rowHeights = len(data) * [15]
    return Table(data, rowHeights=rowHeights, style=style)

Thanks for your help,
Tom


More information about the reportlab-users mailing list