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 3-10. Example of 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 to HTML:
Table 3-1. Mouse Mileage
Month | Week | Feet Traveled |
---|---|---|
August | 1 | 987 |
August | 2 | 657 |
August | 3 | 109 |
Total | 1753 |