How are rows and columns defined in a DITA table?
November 10, 2023
|By Bryan Tipper
In DITA XML, table rows and columns are handled using specific elements to create structured and organized tabular content. DITA provides elements for defining tables, rows, columns, and cells, allowing authors to present data in a structured format.
Working with Tables in DITA:
Uses the <table>, <tgroup>, <colspec>, <tbody>, <row>, and <entry> elements.
- <table>: This is the root element for creating tables in DITA. It defines the entire table structure.
- <tgroup>: The <table> element contains one or more <tgroup> elements, each representing a table group. A table group can have its own attributes and may contain one or more <colspec> and <tbody> elements.
- <colspec>: Inside a <tgroup>, <colspec> elements are used to define the attributes and properties of columns within the table. These elements specify the width, alignment, and other column-specific settings.
- <tbody>: The <tbody> element represents the body of the table and contains one or more <row> elements.
- <row>: Inside a <tbody>, <row> elements are used to define individual rows within the table.
- <entry>: Inside a <row>, the <entry> element represents a cell or entry in the table. It can contain text, lists, or other elements.
Example:
<table>
<tgroup cols="3">
<colspec colname="col1" colnum="1" colwidth="20%"/>
<colspec colname="col2" colnum="2" colwidth="40%"/>
<colspec colname="col3" colnum="3" colwidth="40%"/>
<tbody>
<row>
<entry>Header 1</entry>
<entry>Header 2</entry>
<entry>Header 3</entry>
</row>
<row>
<entry>Data 1</entry>
<entry>Data 2</entry>
<entry>Data 3</entry>
</row>
<row>
<entry>Data 4</entry>
<entry>Data 5</entry>
<entry>Data 6</entry>
</row>
</tbody>
</tgroup>
</table>
In this example:
- <table> defines the entire table structure.
- <tgroup> represents the table group and specifies that the table has three columns.
- <colspec> elements define the properties of each column, including width.
- <tbody> contains the rows of the table.
- <row> elements define individual rows.
- <entry> elements represent cells within each row, containing the table data.