user3782125
user3782125

Reputation: 23

Table with columns of different sizes in two rows

I was planning to use FOP to create a table structure like this:

|_Column1____2cm_|_Column2_2cm_|_Column3___3cm___|

|_Column4_2ndRow____3cm__|_Column5_2ndRow___4cm__|

As you may or may not see (depending on how this is displayed), I'm trying to have two rows of columns with different widths: the first column in the first row is bigger than the column directly under it in the second row, so this is not a traditional table design but some kind of an "asymmetric" table.

I would like to ask you if this is achievable with FOP at all, and if so, if you have any tips on how to do it.

Upvotes: 2

Views: 1416

Answers (1)

Andreas
Andreas

Reputation: 159165

It is achievable with FOP.

If you know HTML <table>, then FOP tables work very much the same.

In your case you create a 4 column, 2 row table, then use colspan to "merge" some of the cells.

┌───────┬───────┬───────┬───────┐
│       │  colspan="2"  │       │
├───────┼───────┼───────┼───────┤
│  colspan="2"  │  colspan="2"  │
└───────┴───────┴───────┴───────┘

In HTML, that would be:

<table border="1" style="border-collapse: collapse">
  <tr>
    <td style="width: 2cm">X</td>
    <td style="width: 2cm" colspan="2">X</td>
    <td style="width: 3cm">X</td>
  </tr>
  <tr>
    <td style="width: 3cm" colspan="2">X</td>
    <td style="width: 4cm" colspan="2">X</td>
  </tr>
</table>

My XSL-FO is a bit rusty, but it should be something like:

<fo:table>
  <fo:table-column column-width="2cm"/>
  <fo:table-column column-width="1cm"/>
  <fo:table-column column-width="1cm"/>
  <fo:table-column column-width="3cm"/>
  <fo:table-body>
    <fo:table-row>
      <fo:table-cell><fo:block>X</fo:block></fo:table-cell>
      <fo:table-cell number-columns-spanned="2"><fo:block>X</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>X</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell number-columns-spanned="2"><fo:block>X</fo:block></fo:table-cell>
      <fo:table-cell number-columns-spanned="2"><fo:block>X</fo:block></fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>

As you can see, very similar to the HTML.

Upvotes: 3

Related Questions