The Crash Course to DocBook

Chapter 7. Tables

The tags covered in this section are listed below.

table - Table in a document
informaltable - Untitled table
thead - Heading row of a table
tfoot - Footer row of a table
tgroup - Wrapper for part of a table that contains an array along with its formatting information
tbody - Wrapper for the rows of a table or informaltable
row - Row in a tbody, thead, or tfoot
entry - Cell in a table
entrytbl - Subtable appearing as a table cell

Tables are used to organize data into a columnar format with optional titles, headers, and footers. 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.

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. This tutorial will only cover the basic formatting attributes. For more details, you should refer to the DocBook Reference.

Tables begin with the <table> or <informaltable> tag. Next, define a title using the <title> tag if you are using a regular table. Finally, we get to the <tgroup> tag which contains all of the header, footer, and row information. You can have more than one tgroup if you wish to change formatting options for a section of the table. The <tgroup> tag has a number of optional formatting parameters, but the COLS attribute, which specifies the number of columns, is required. The <thead>, <tfoot>, and <tbody> 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, labelled with the <row> and <entry> tags respectively. Use the <row> tag to begin a row, an <entry> tag for each item of data, and a closing <row> tag to end that row. If you want to embed a table within a table, you must use the <entrytbl> tag.

Example 7-1. A table

 
<table>
<title>Mouse Mileage</title>
<tgroup cols="3">
<thead>
<row>
<entry>Month</entry>
<entry>Week</entry>
<entry>Feet Traveled</entry>
</row>
</thead>
<tfoot>
<row>
<entry>Total</entry>
<entry></entry>
<entry>1753</entry>
</row>
</tfoot>
<tbody>
<row>
<entry>August</entry>
<entry>1</entry>
<entry>987</entry>
</row>
<row>
<entry>August</entry>
<entry>2</entry>
<entry>657</entry>
</row>
<row>
<entry>August</entry>
<entry>3</entry>
<entry>109</entry>
</row>
</tbody>
</tgroup>
</table> 

The above example would look something like this when converted:

Table 7-1. Mouse Mileage

MonthWeekFeet Traveled
August1987
August2657
August3109
Total 1753