How do you define table headers and footers in DITA?

In DITA, table headers and footers can be defined using specific elements to provide context and additional information to table content.

Table Headers:

Table headers provide context to the columns in a table. In DITA, table headers are typically placed at the beginning of a table within a <thead> element. The <row> and <entry> elements can be used to define header content for each column.

Example:

This is a sample of how table headers might be defined.


<table>
  <title>Sample Table with Headers</title>
  <tgroup cols="3">
    <thead>
      <row>
        <entry>Header 1</entry>
        <entry>Header 2</entry>
        <entry>Header 3</entry>
      </row>
    </thead>
    <tbody>
      <!-- Table body rows and data -->
    </tbody>
  </tgroup>
</table>

Table Footers:

Table footers provide additional information at the end of a table, such as notes, explanations, or references. In DITA, the <tfoot> element is used to define table footers. Similar to headers, <row> and <entry> elements can be used to structure the footer content.

Example:

This is a sample of how table footers might be defined.


<table>
  <title>Sample Table with Footer</title>
  <tgroup cols="3">
    <thead>
      <row>
        <entry>Header 1</entry>
        <entry>Header 2</entry>
        <entry>Header 3</entry>
      </row>
    </thead>
    <tbody>
      <!-- Table body rows and data -->
    </tbody>
    <tfoot>
      <row>
        <entry>Footer 1</entry>
        <entry>Footer 2</entry>
        <entry>Footer 3</entry>
      </row>
    </tfoot>
  </tgroup>
</table>

Example:

This is a sample of a table with both headers and footers.


<table>
  <title>Sample Table with Header and Footer</title>
  <tgroup cols="3">
    <thead>
      <row>
        <entry>Item</entry>
        <entry>Description</entry>
        <entry>Quantity</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Product A</entry>
        <entry>High-quality product</entry>
        <entry>10</entry>
      </row>
      <row>
        <entry>Product B</entry>
        <entry>Advanced features</entry>
        <entry>5</entry>
      </row>
    </tbody>
    <tfoot>
      <row>
        <entry>Total:</entry>
        <entry/>
        <entry>15</entry>
      </row>
    </tfoot>
  </tgroup>
</table>

In this example, the <thead> element contains column headers, the <tbody> holds the data, and the <tfoot> defines a summary footer for the table.