How to center a table in xsl-fo?

I am trying to center a table in a block element in the 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 result:

enter image description here

How can I center this table in this block?

Thanks.

+4
source share
3 answers

In the specs, a <table> centered using text-align="center" in the parent <table-and-caption> element. The <table-caption> brother is optional and may be omitted, so the table is the only child.

Note that this will not work by placing text-align in the parent <block> ... the child <table> is still a block construct and is not affected. It must be with the parent <table-and-caption> .

I remind my XSL-FO students that they will probably want text-align="start" on their <table> if they also do not want the contents of the table to be centered due to property inheritance on descendant constructions.

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

+5
source

When using Apache FOP, they explain the method of centering the table here: https://xmlgraphics.apache.org/fop/fo.html#fo-center-table-horizon

+1
source

If we have ten columns, we can center the 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> 
+1
source

Source: https://habr.com/ru/post/1499364/


All Articles