VALIGN in reportlab TableStyle apparently without effect
<p>So, for a while now I have been struggling with this one. I know there are a lot of similar questions with good answers, and I have tried these answers, but the code I have basically reflects the answers given.</p>

<p>I am writing code to automatically generate matching exercises for worksheets. All this information should be in a table. And the text should all be aligned to the top of the cells.</p>

<p>Here is what I have now:</p>

<pre><code>from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table,         TableStyle
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm

document = []
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()

definitions = []
i, a = 1, 65
table = []
for x in range(1, 10):
    line = []
    line.append(Paragraph(str(i), styles['BodyText']))
    line.append(Paragraph('Vocabulary', styles['BodyText']))
    line.append(Paragraph(chr(a), styles['BodyText']))
    line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
    table.append(line)
    i += 1
    a += 1

t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
    ('VALIGN', (1, 1), (-1, -1), 'TOP')
]))

document.append(t)
doc.build(document)
</code></pre>

<p>What am I overlooking?</p>

<p>The problem is the way you are indexing the <code>TableStyle</code>. The indexing in Reportlab starts at <code>(0, 0)</code> for first row, first column. So in your case <code>(1, 1)</code> only applies the styling to everything below the first row and right of the first column.</p>

<p>The correct way would be to use:</p>

<pre><code>('VALIGN', (0, 0), (-1, -1), 'TOP')
</code></pre>

<p>This will apply the styling to all cells in the <code>Table</code>.</p>

python formatting reportlab