Tables are used to organize data into a columnar representation. Optional titles, headers, and footers can be added to for describing the data, as required. DocBook tables come in two varieties: the table, which requires a title, and the informaltable, which does not have a title. All the other characteristics of these two table types are the same. DocBook elements associated to table markup are detailed below.
A table consists of formatting information and data entries. There are quite a few attributes that can be adjusted to tweak the display of your data. The examples show only a few of the basic formatting attributes. For more detailed description is in the DocBook Reference documentation.
Let us look at an example to see how a table is constructed.
Example 4.1. A regular simple table
1 <table> <title>Number of Visitors</title> <tgroup cols="3"> <thead> 5 <row> <entry>Month</entry><entry>Week</entry><entry>Visitors</entry> </row> </thead> <tfoot> 10 <row> <entry>Total</entry><entry></entry><entry>1833</entry> </row> </tfoot> <tbody> 15 <row> <entry>March</entry><entry>1</entry><entry>634</entry> </row> <row> <entry>March</entry><entry>2</entry><entry>657</entry> 20 </row> <row> <entry>March</entry><entry>3</entry><entry>542</entry> </row> </tbody> 25 </tgroup> </table>
As shown in Example 4.1, tables begin with the <table> (or <informaltable>) tag. Next, a title has to be defined using the title tag when using a regular table (line 2). Finally, we have the tgroup element which contains all of the header, footer, and row information (lines 3 to 25). There can be more than one tgroup if formatting options have to change for the different sections of the table. The tgroup tag (line 3) has a number of optional formatting parameters, but the cols attribute, which specifies the number of columns, is required. The thead (lines 4 to 8), tfoot (lines 9 to 13), and tbody (lines 14 to 24) elements contain the data in your table. Data in the thead appears at the top of the table, tbody appears in the middle, and tfoot appears at the end of the table.
Data in a table is contained in rows and entries, using row (lines 5-7, 10-12, 15-17, etc.) and entry (lines 6, 11, 16, etc.) elements, respectively. A table can be embedded inside another with the entrytbl element.
The above example would look something like this when converted:
Table 4.1. Number of Visitors