How are tables created in DITA XML?

Creating tables in DITA XML is a valuable technique for presenting structured data in documentation. Tables are commonly used for displaying various types of information, such as product specifications, comparative data, or any content that benefits from a tabular format. Here’s an overview of how tables are created in DITA XML.

Table Structure

In DITA XML, tables are structured using elements like <table>, <tgroup>, and <row>. The <table> element defines the entire table, while the <tgroup> element contains the table structure, specifying the number of columns and their properties. Rows within the table are defined using the <row> element. Cells in each row are represented by the <entry> element. This structured approach allows you to create tables with multiple rows and columns, ensuring that your tabular data is well-organized.

Column Specifications

DITA XML allows you to specify various attributes for table columns, such as column width and alignment. These attributes provide control over the visual presentation of the table. The <colspec> element is used to define column specifications. You can set attributes like colwidth to specify the width of individual columns and align to define column alignment (e.g., left, right, center). This enables you to create tables that meet your specific formatting requirements.

Example:

Here’s an example of how a table is created in DITA XML:


<table>
  <tgroup cols="3">
    <colspec colname="col1" colwidth="30%" />
    <colspec colname="col2" colwidth="40%" />
    <colspec colname="col3" colwidth="30%" />
    <tbody>
      <row>
        <entry>Product</entry>
        <entry>Specifications</entry>
        <entry>Price</entry>
      </row>
      <row>
        <entry>Product A</entry>
        <entry>Details for Product A</entry>
        <entry>$199.99</entry>
      </row>
      <row>
        <entry>Product B</entry>
        <entry>Details for Product B</entry>
        <entry>$149.99</entry>
      </row>
    </tbody>
  </tgroup>
</table>

In this example, a simple table is created to display product information with three columns: Product, Specifications, and Price. The table structure is defined using DITA XML elements, including <table>, <tgroup>, <tbody>, and <row>. Column specifications are set using <colspec> elements, allowing you to control column width and alignment.