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:

How can I center this table in this block?
Thank you.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With