There are two elements used for placing tables inside a DocBook document, table and informaltable, the only difference between the former and the latter is that the former requires a title and the latter does not.
<table><title>title</title> <informaltable>
. .
. or .
. .
</table> </informaltable>
|
The table contains an attribute called frame which specifies how the table should be framed:
<table frame="frametype"><title>frame="frametype"</title>
<tgroup cols="1">
<thead>
<row><entry>a1</entry><entry>b1</entry><entry>c1</entry></row>
</thead>
<tbody>
<row><entry>a2</entry><entry>b2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</table>
|
Where frametype is replaced with one of all, bottom, none, sides, top or topbot:
The output above is PDF, with HTML all the tables look the same as the one with attribute all apart from the one with attribute none which has no frame at all. The attributes colsep and rowsep are used to control whether lines should be drawn between columns and rows respectively:
<table colsep="0" rowsep="0"> ... </table>
<table colsep="0" rowsep="1"> ... </table>
<table colsep="1" rowsep="0"> ... </table>
<table colsep="1" rowsep="1"> ... </table>
|
Unfortunately at the time of writing the tools used to convert FO to PDF either did not yet implement this feature or were in a broken state with regards to this feature so no pictorial examples can be provided. Other table attributes are discussed at http://www.docbook.org/tdg/en/html/table.html.
The generic layout for a table is as follows:
<table><title>title</title>
<tgroup cols="3">
<thead>
<row><entry>blah</entry></row>
</thead>
<tbody>
<row><entry>blah</entry></row>
</tbody>
<tfoot>
<row><entry>blah</entry></row>
</tfoot>
</tgroup>
</table>
|
tgroup contains the rest of the table which must contain a tbody element which specifies which data is in the body of the table. The tbody element may be empty with the table being included in thead or tfoot but this is not the intention. The reason for the thead and tfoot elements is so that different layouts can be applied by the stylesheets for the header and the footer of the table respectively. So usually the first row would be wrapped in a thead element. tgroup has the mandatory attribute cols which specifies the number of columns the table has.
tgroup may also specify alignment of content via the align attribute, where alignment is either left, center or right:
<table frame="all"><title>align="alignment"</title>
<tgroup cols="3" align="alignment">
<tbody>
<row><entry>a2</entry><entry>b2</entry><entry>c2</entry></row>
</tbody>
</tgroup>
</table>
|
For more information about the tgroup element see http://www.docbook.org/tdg/en/html/tgroup.html.
A row consists of a number of entry elements which are entered in the sequence they should appear in each table row, for more information about the row element see http://www.docbook.org/tdg/en/html/row.html.
The entry element has some interesting attributes which allow an entry to span more than one column or row, they are (namest & nameend) and morerows respectively. The morerow attribute specifies how many more rows the entry it is applied to should span:
<table frame="all"><title><emphasis>morerows</emphasis> example</title>
<tgroup cols="3">
<tbody>
<row><entry morerows="2">a1</entry><entry>b1</entry><entry>c1</entry></row>
<row><entry>b2</entry><entry>c2</entry></row>
<row><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</table>
|
Unfortunately there is no morecolumns attribute, instead one has to use namest to specify the starting column of the entry and nameend to specify the ending column of the entry. The value applied to this attribute is the name of the columns, columns are named using the colspec element, colspec elements are inserted inside tgroup but before thead, tbody and tfoot:
<table frame="all"><title>column spanning</title>
<tgroup cols="3">
<colspec colname="col1"/>
<colspec colname="col2"/>
<colspec colname="col3"/>
<tbody>
<row><entry namest="col1" nameend="col3">a1</entry></row>
<row><entry>a2</entry><entry>b1</entry><entry>c1</entry></row>
<row><entry>a3</entry><entry>b2</entry><entry>c2</entry></row>
</tbody>
</tgroup>
</table>
|
More information about the entry element can be found at http://www.docbook.org/tdg/en/html/entry.html. Tables may be nested to a level of one, see http://www.docbook.org/tdg/en/html/entrytbl.html. For the entire source and output pertaining to the examples discussed in this section see Table Examples.