Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center table in xsl-fo?

Tags:

css

xml

xslt

xsl-fo

I am trying to center a table in a block element in a xsl-fo namespace.

Here is what I am trying:

 <fo:block margin-right="auto" margin-left="auto" background-color="#eaeaea">
     <fo:table margin-top="1cm" margin-left="auto" margin-right="auto" margin-bottom="1cm" width="auto">

And this is the output:

enter image description here

How can I center this table in this block?

Thank you.

like image 746
Koray Tugay Avatar asked Aug 28 '13 11:08

Koray Tugay


2 Answers

Per the specification, a <table> is centred by using text-align="center" on a parent <table-and-caption> element. The <table-caption> sibling is optional and can be omitted such that the table is the only child.

Note this will not work by putting text-align on a parent <block> ... a child <table> is still a block-level construct and is not affected. It has to be on the parent <table-and-caption>.

I remind my XSL-FO students that they likely will want a text-align="start" on their <table> unless they also want the contents of the table to be centred due to the inheritance of the property on descendant constructs.

I should note a postscript based on my commercial work that not all XSL-FO processors support the specification in this regard.

like image 73
G. Ken Holman Avatar answered Sep 28 '22 08:09

G. Ken Holman


If we have ten columns then we can center table as follows

<fo:table width="100%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
  <fo:table-column column-width="10%">
 </fo:table>
like image 27
Ferdous Islam Avatar answered Sep 28 '22 07:09

Ferdous Islam