<colspec>: How do you use the <colspec> element to specify column specifications and formatting for DITA tables?

The <colspec> element in DITA XML is used to specify column specifications and formatting for tables. It allows you to define the characteristics of individual columns within a table, such as their width, alignment, and other formatting attributes. Using <colspec> elements, you can create well-structured and visually appealing tables to present tabular data in your DITA topics.

Column Specifications

To use the <colspec> element, you include it within the <tgroup> element, which represents the group of columns in a table. Each <colspec> element can have various attributes to define column properties. Common attributes include “colname” to assign a name to the column, “colnum” to specify the column number, “colwidth” to set the width of the column, and “colsep” and “rowsep” to control the column and row separators.

Example:

Here’s an example of how to use the <colspec> element to specify column specifications for a DITA table:


<table>
  <tgroup cols="3">
    <colspec colname="col1" colwidth="25%" />
    <colspec colname="col2" colwidth="40%" />
    <colspec colname="col3" colwidth="35%" />
    <thead>
      <row>
        <entry>Product</entry>
        <entry>Description</entry>
        <entry>Price</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Product A</entry>
        <entry>A high-quality product</entry>
        <entry>$99.99</entry>
      </row>
      <row>
        <entry>Product B</entry>
        <entry>Our latest offering</entry>
        <entry>$149.99</entry>
      </row>
    </tbody>
  </tgroup>
</table>

In this example, the <colspec> elements within the <tgroup> element specify the column specifications for a 3-column table. The “colwidth” attribute is used to define the width of each column, ensuring that the table is visually organized and formatted according to your requirements.