What is the purpose of the <tgroup> element in DITA tables?

In DITA, the <tgroup> element serves the purpose of defining a table group within a <table>. It is a crucial element for structuring and organizing tables, allowing specification of attributes and properties that apply to the entire group of columns within a table. The <tgroup> element is part of the DITA table model, which helps maintain consistency and structure in tabular content.

Role of the <tgroup> Element:

The <tgroup> element affects column configuration, properties, and structural organization.

Column Configuration:

The <tgroup> element can specify the number of columns in the table, allowing the structure of the table to be defined. The cols attribute can be used to indicate the total number of columns in the table group.

Column Properties:

Within a <tgroup>, <colspec> elements can be included to configure the properties of individual columns. These elements allow setting attributes such as column width, alignment, and other properties. Each <colspec> element corresponds to a specific column in the table.

Structural Organization:

By grouping columns using the <tgroup> element, the table’s structure can be effectively organized. This makes it easier to manage and maintain complex tables, ensuring that attributes and properties are applied consistently across related columns.

Example:


        <table>
            <title>Sample Table</title>
            
            <!-- Define a table group with three columns -->
            <tgroup cols="3">
                <!-- Define properties for the first column -->
                <colspec colname="col1" colnum="1" colwidth="20%"/>
                
                <!-- Define properties for the second column -->
                <colspec colname="col2" colnum="2" colwidth="40%"/>
                
                <!-- Define properties for the third column -->
                <colspec colname="col3" colnum="3" colwidth="40%"/>
                
                <!-- Include table body (tbody) and rows here -->
            </tgroup>
            
            <!-- Include table body content within the table -->
            <tbody>
                <row>
                    <entry>Data 1</entry>
                    <entry>Data 2</entry>
                    <entry>Data 3</entry>
                </row>
                <!-- More rows... -->
            </tbody>
        </table>
    

In this example:

  • The <tgroup> element defines a table group with three columns using the cols attribute.
  • Three <colspec> elements configure the properties for each column.
  • The table body (<tbody>) is included within the <table> to define the rows and cells of the table.