[reportlab-users] Problem with row&column spanning code not calculating table heights

Robin Becker reportlab-users@reportlab.com
Wed, 15 Oct 2003 17:04:46 +0100


In article <PGECLPOBGNBNKHNAGIJHIENEFJAA.andy@reportlab.com>, Andy
Robinson <andy@reportlab.com> writes
>> Hi
>> 
>> In reportlab 1.18 we have a problem where the last row of a table has no 
>> height - the text appears, but the boxes are all squashed (see the 
>> screenshots below for comparison).
>> We have tracked this down to some code in platypus/tables.py where the 
>> code says to ignore a cell for calculating row height if the cell is 
>> part of a span.
>> Taking out this code fixes our problem (see the attached patch)
>> We have had some related problems with row and column spanning; can 
>> anyone comment on this?
>
>I guess what we should say is,
>  "ignore cell for row height if part of a span AND IT SPANS MORE 
>   THAN ONE ROW"
>
>And the corollary is to ignore cells when calculating width ig
>they span more than one column.
....
gurk. I believe it's more complicated

Suppose we have two rows and two columns

11 12
21 22

If say the second column is actually a cell that spans two rows the
implication is that

row1.height >= c11 = max(cell11.height,0)
row2.height >= c21 = max(cell21.height,0)
row1.height+row2.height >= c1222 = max(cell12&22.height,0)

We can solve this as a linear program variables being row1.height,
row2.height. The utility would normally be the total height ie
row1.heigth+row2.height which we attempt to minimize. In this simple
case there are only a few ways that the constraints can be binding.
In particular we know the optimal cost

U = max(c11+c21,c1222)

but if that is not c11+c21 then we still don't get the optimal row
heights as they are not bound at the solution. So if

if c11+c21<c1222:
    if c11+c21>0: 
      choose heights c11*U/(c11+c21), U-c11*U/(c11+c21)
    else:
      choose heights 0, U
else:
    choose heights c11, c21

Of course this is about the simplest possible row spanning problem. In a
more general problem with multiple overlapping spans we can still solve
the LP formulation to get the required minimum required overall heights.
I'm not sure if there's a simple general formulation that is easy to
solve.
-- 
Robin Becker