You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Karl Roberts <Ka...@macquarie.com> on 2006/03/07 00:28:05 UTC

Howto align tables to fill width

Hi all,

I have some XML that defines TabularData elements, which represent
tabular data. In some cases the data can includes information on the
column widths in order to guarentee that the data fit's in it.

Eg

<TabularData>
	<MetaData>
		<!-- mandatory fields from schema -->
		<TableID>freshmoney</TableID>
		<TableTitle>Fresh Money IDEAs</TableTitle>
		<NumColumns>5</NumColumns>
		<NumRows>20</NumRows>
		<ColumnTitleRowNum>0</ColumnTitleRowNum>
		
		<!-- optional fields from schema -->
<!-- nb the width should be calculated from fontmetrics, use (num of
chars * 0.6 for now) -->
		<Column num="1" width="7.8" text-justify="left"/>
		<Column num="2" width="2.6" text-justify="left"/>
		<Column num="3" width="3.6" text-justify="right"/>
		<Column num="4" width="4.2" text-justify="right"/>
		<Column num="5" width="2.4" text-justify="right"/>
	</MetaData>
	
	<Cell xpos="0" ypos="0">ColHeader1</Cell>
	<Cell xpos="1" ypos="0">CH2</Cell>
	<Cell xpos="2" ypos="0">Col3 Price</Cell>
	<Cell xpos="3" ypos="0">Header4</Cell>
	<Cell xpos="4" ypos="0">Head 5</Cell>
	<Cell xpos="0" ypos="1">Chartered Semiconductor</Cell>
	<Cell xpos="1" ypos="1">OP</Cell>
	<Cell xpos="2" ypos="1">1.5</Cell>
	<Cell xpos="3" ypos="1">1.29</Cell>
	<Cell xpos="4" ypos="1">16</Cell>
	...
	...
</TabularData>

I have an xsl template that can turn all this into a nice table and if
the data contains <Column> elements I use xsl like this ...

<fo:table table-layout="fixed" width="100%">
<xsl:for-each select="MetaData/Column">
	<xsl:sort select="self::node()/@num" data-type="number"/>
	<fo:table-column column-number="{self::node()/@num}"
		column-width="{self::node()/@width-in-em}em"/>
</xsl:for-each>
<fo:table-body> ... </fo:table-body>
...
</fo:table>

I works fine. However when the table width is greater than the sum of
the widths I'd like to widen the columns (or just the first one) to fill
the available space. Given that the xsl to produce a table is in a call
and hence the table width is given as 100% (of space available to the
<fo:block/> that it is enclosed inanyone have a clue how to do this?

If it helps I'll post the schema and xsl-fo template for the table.

Cheers

Karl


NOTICE
This e-mail and any attachments are confidential and may contain copyright material of Macquarie Bank or third parties. If you are not the intended recipient of this email you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. Macquarie Bank does not guarantee the integrity of any emails or any attached files. The views or opinions expressed are the author's own and may not reflect the views or opinions of Macquarie Bank.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Howto align tables to fill width

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
What you describe is actually something that FOP is supposed to do
automatically but so far hasn't learned to do. This is described in [1]
for the fixed table layout. At the moment, you probably need to do some
calculation in XSLT and add to the column widths yourself.

[1] http://www.w3.org/TR/REC-CSS2/tables.html#width-layout

On 07.03.2006 00:28:05 Karl Roberts wrote:
> Hi all,
> 
> I have some XML that defines TabularData elements, which represent
> tabular data. In some cases the data can includes information on the
> column widths in order to guarentee that the data fit's in it.
> 
> Eg
> 
> <TabularData>
> 	<MetaData>
> 		<!-- mandatory fields from schema -->
> 		<TableID>freshmoney</TableID>
> 		<TableTitle>Fresh Money IDEAs</TableTitle>
> 		<NumColumns>5</NumColumns>
> 		<NumRows>20</NumRows>
> 		<ColumnTitleRowNum>0</ColumnTitleRowNum>
> 		
> 		<!-- optional fields from schema -->
> <!-- nb the width should be calculated from fontmetrics, use (num of
> chars * 0.6 for now) -->
> 		<Column num="1" width="7.8" text-justify="left"/>
> 		<Column num="2" width="2.6" text-justify="left"/>
> 		<Column num="3" width="3.6" text-justify="right"/>
> 		<Column num="4" width="4.2" text-justify="right"/>
> 		<Column num="5" width="2.4" text-justify="right"/>
> 	</MetaData>
> 	
> 	<Cell xpos="0" ypos="0">ColHeader1</Cell>
> 	<Cell xpos="1" ypos="0">CH2</Cell>
> 	<Cell xpos="2" ypos="0">Col3 Price</Cell>
> 	<Cell xpos="3" ypos="0">Header4</Cell>
> 	<Cell xpos="4" ypos="0">Head 5</Cell>
> 	<Cell xpos="0" ypos="1">Chartered Semiconductor</Cell>
> 	<Cell xpos="1" ypos="1">OP</Cell>
> 	<Cell xpos="2" ypos="1">1.5</Cell>
> 	<Cell xpos="3" ypos="1">1.29</Cell>
> 	<Cell xpos="4" ypos="1">16</Cell>
> 	...
> 	...
> </TabularData>
> 
> I have an xsl template that can turn all this into a nice table and if
> the data contains <Column> elements I use xsl like this ...
> 
> <fo:table table-layout="fixed" width="100%">
> <xsl:for-each select="MetaData/Column">
> 	<xsl:sort select="self::node()/@num" data-type="number"/>
> 	<fo:table-column column-number="{self::node()/@num}"
> 		column-width="{self::node()/@width-in-em}em"/>
> </xsl:for-each>
> <fo:table-body> ... </fo:table-body>
> ...
> </fo:table>
> 
> I works fine. However when the table width is greater than the sum of
> the widths I'd like to widen the columns (or just the first one) to fill
> the available space. Given that the xsl to produce a table is in a call
> and hence the table width is given as 100% (of space available to the
> <fo:block/> that it is enclosed inanyone have a clue how to do this?
> 
> If it helps I'll post the schema and xsl-fo template for the table.
> 
> Cheers
> 
> Karl


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org