What elements are used to create rows and columns in DITA tables?

In DITA, tables are used to organize content into rows and columns. Creating tables involves specific elements for defining rows and columns.

These elements are <table>, <tgroup>, and <colspec>.

<table> Element:

The <table> element is the root element for defining tables in DITA. It contains one or more <tgroup> elements, each representing a table group. A DITA table is typically comprised of a single <table> element.

<tgroup> Element:

The <tgroup> element is used to group rows and columns within a table. It can contain one or more <colspec> elements, defining the table’s column specifications. A <tgroup> can contain <thead> (header) and <tbody> (body) elements, which organize the content.

<colspec> Element:

The <colspec> element is used to define the characteristics of individual columns in a table, such as width and alignment. It is typically found within a <tgroup> element.

Example:

This is a sample of a simple table in DITA.


<table>
  <title>Sample Table</title>
  <tgroup cols="3">
    <colspec colname="col1" colwidth="30%"/>
    <colspec colname="col2" colwidth="40%"/>
    <colspec colname="col3" colwidth="30%"/>
    <thead>
      <row>
        <entry>Header 1</entry>
        <entry>Header 2</entry>
        <entry>Header 3</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Row 1, Column 1</entry>
        <entry>Row 1, Column 2</entry>
        <entry>Row 1, Column 3</entry>
      </row>
      <row>
        <entry>Row 2, Column 1</entry>
        <entry>Row 2, Column 2</entry>
        <entry>Row 2, Column 3</entry>
      </row>
    </tbody>
  </tgroup>
</table>

In this example, we’ve created a simple table with a <table> element that contains a <tgroup>. The <tgroup> has three <colspec> elements to define column specifications. It also includes <thead> for the table header and <tbody> for the table body. Rows are defined within the <tbody> using the <row> element, and individual cells (entries) are defined within the rows.