I am trying to insert two tables in the pdf using python reportlab.
Number of rows in the second table are less than first table.
But the horizontal position of the two tables is not matching.
Some empty space coming on the second table.
How can I remove this space so that both the tables will come horizontally aligned?
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
doc = SimpleDocTemplate("simple_table_grid.pdf", pagesize=letter)
elements = []
data= [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
data1= [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14']]
t1=Table(data,5*[0.4*inch], 4*[0.4*inch],hAlign='LEFT')
t1.setStyle(TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
('TEXTCOLOR',(1,1),(-2,-2),colors.red),
('VALIGN',(0,0),(0,-1),'TOP'),
('TEXTCOLOR',(0,0),(0,-1),colors.blue),
('ALIGN',(0,-1),(-1,-1),'CENTER'),
('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
t2=Table(data1,5*[0.4*inch], 2*[0.4*inch],hAlign='RIGHT')
t2.setStyle(TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
('TEXTCOLOR',(1,1),(-2,-2),colors.red),
('VALIGN',(0,0),(0,-1),'TOP'),
('TEXTCOLOR',(0,0),(0,-1),colors.blue),
('ALIGN',(0,-1),(-1,-1),'CENTER'),
('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
t = [[t1,t2]]
temp = Table(t)
elements.append(temp)
doc.build(elements)
well, there is a workaround for it. You can add your tables in another table with two columns and a single row. Something like this..