Multicolumn - automatic line breaks
sedirmohammed opened this issue · comments
I noticed that in the Multicolumn environment the automatic line breaks do not work. If I set the width of the columns, then still no line break is set and the width of the columns is increased.
table = LongTable('p{2cm} p{1cm} p{1cm}')
table.add_hline()
table.add_row(['A','B','C'])
table.end_table_header()
table.add_row(['123',MultiColumn(2, align='c', data='Hello, this is a little test for the MultiColumn-Environment.')])
table.add_hline()
I found out how this works.
It is theoretically possible via the align
attribute to use p
formatting to specify the width of the MultiColumn.
So like this:
table.add_row(['123',MultiColumn(2, align='p{2cm}', data='Hello, this is a little test for the MultiColumn-Environment.')])
However, this results in an error when generating the pdf. The problem becomes apparent when you look at the generated .tex file:
123&\multicolumn{2}{p\{2cm\}}{Hello, this is a little test for the MultiColumn{-}Environment.}\\%
The curly braces in p
are escaped! In table.py, in the MultiColumn class, the call to NoEscape(align)
is missing at the point self.align = align
, it should be self.align = NoEscape(align)
. You can work around this by calling NoEscape()
in align
when you create the MultiColumn. So this should work:
table.add_row(['123',MultiColumn(2, align=NoEscape('p{2cm}'), data='Hello, this is a little test for the MultiColumn-Environment.')])