Chapter 4. Tables

Table of Contents

4.1. A simple table
4.2. An informal table
4.3. A more complex table with some math

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.

4.1. A simple table

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">
  5       <row>
 10       <row>
 15       <row>
 20       </row>
 25   </tgroup>

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

Total 1833