13
votes

As it stands now, I have about 12 columns and all of them are exactly the same width. The problem is that some columns don't require that much space. How do I get the columns to fit their content? The columns need to be a dynamic width.

I've tried

<fo:table table-layout="auto">

And

<fo:table-column column-width="proportional-column-width(1)" column-number="1"/>
<fo:table-column column-width="proportional-column-width(1)" column-number="2"/>
<fo:table-column column-width="proportional-column-width(1)" column-number="3"/>

Nothing seems to do the trick.

3
If you are using FOP, it won't work. FOP doesn't support table-layout="auto". - mzjn
Thanks! Any idea for the question itself? - SeanWM
Buy a commercial formatter that supports table-layout="auto", such as XEP (renderx.com/tools/xep.html). There are also free personal and academic editions for non-commercial use: renderx.com/download/personal.html. - mzjn

3 Answers

15
votes

Unfortunately I didn't find a simple way to have dynamic column widths. I ended up with this:

<fo:table-column column-number="1"  column-width="35pt" />
<fo:table-column column-number="2"  />
<fo:table-column column-number="3"  />
<fo:table-column column-number="4"  />
<fo:table-column column-number="5"  />
<fo:table-column column-number="6"  />
<fo:table-column column-number="7"  />
<fo:table-column column-number="8"  />
<fo:table-column column-number="9"  />
<fo:table-column column-number="10" />
<fo:table-column column-number="11" />
<fo:table-column column-number="12" />

I specify the first column because the data will never change. The rest I leave open to fit their content. Works the way I need it to work for now.

3
votes

You can also specify the units in "percent units". Works fine for me...

<fo:table-column column-number="1" column-width="75%" /> 
<fo:table-column column-number="2" column-width="25%" />
0
votes
  1. Use the attribute 'proportional-column-width' for lengthy columns and remaining columns let be default.
  2. Check the width of the each columns, If it is lengthy than other columns, provide how many times bigger (like 2 times or 3 times or 4.5 times or even more).

Ex-1 :

<fo:table-column column-number="1" column-width="proportional-column-width(3)"/>
<fo:table-column column-number="2"/>
<fo:table-column column-number="3"/>

Ex-2 :

<fo:table-column column-number="1" column-width="proportional-column-width(3)"/>
<fo:table-column column-number="2" column-width="proportional-column-width(4)"/>
<fo:table-column column-number="3"/>