Koray Tugay
Koray Tugay

Reputation: 23780

How to center table in 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.

Upvotes: 7

Views: 14368

Answers (4)

wavedbabe
wavedbabe

Reputation: 23

you can simply add styles right to the xsl page!

Upvotes: -1

Ferdous Islam
Ferdous Islam

Reputation: 75

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>

Upvotes: 1

Rob Stoecklein
Rob Stoecklein

Reputation: 989

If using Apache FOP, they explain a table centering technique here: https://xmlgraphics.apache.org/fop/fo.html#fo-center-table-horizon

Upvotes: 2

G. Ken Holman
G. Ken Holman

Reputation: 4393

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.

Upvotes: 9

Related Questions