<table>: How do you use the <table> element to create structured tables for presenting tabular data in a DITA topic?

Structured tables are a fundamental part of presenting tabular data effectively in DITA topics. The <table> element allows you to create organized and structured tables that can be used to display various types of data, such as product specifications, pricing information, or comparative data.

Creating Tables

To create a table in DITA XML, you use the <table> element along with its child elements. The basic structure of a table consists of <tgroup>, <colspec>, <thead>, <tbody>, and <row> elements. The <colspec> element defines the number and width of columns, the <thead> element contains the table header, and the <tbody> element holds the table body. Within the <row> elements, you define individual rows, and within each row, you use <entry> elements to specify the content of each cell. Attributes like “colname” and “align” can be used to further customize the table and its cells.


Here’s an example of how to create a structured table in DITA:

  <tgroup cols="3">
    <colspec colname="col1" colwidth="25%" />
    <colspec colname="col2" colwidth="40%" />
    <colspec colname="col3" colwidth="35%" />
        <entry>Product A</entry>
        <entry>A high-quality product</entry>
        <entry>Product B</entry>
        <entry>Our latest offering</entry>

In this example, we’ve created a table with three columns: Product, Description, and Price. The <thead> section defines the column headers, and the <tbody> section contains the data rows. Each cell’s content is defined using the <entry> element, and we’ve specified column widths and names using <colspec> attributes.