Tables
Tables provide grid-formatting of related data, where eeach row is an item, and each column provides information about the item.
Use table elements and class formatting to define how tables look when published.
Table with heading row
Headings identify the data in the column. Headings are optional; included them as needed.
| Names | Values |
|---|---|
| a | 123 |
| b | 687 |
| c | 488 |
No heading row
Omit heading when the table contents is obvious based on the surround context.
| a | 123 |
| b | 687 |
| c | 488 |
Table with a title
Only include a title when necessary for referencing the table in text. And then it is best to include a link to the table, like for This is a table title.
| Name | Value |
|---|---|
| Mike | Awesome |
| Other | OK |
Table full-width, unequal column widths
Create a table that fills the 100% the width of the content column by assigning table-full-width to the outputclass attribute for the <table> element.
| Names | Description |
|---|---|
| a | Some reasonable textual description. |
| b | 687 |
| c | 488 |
Table with equal-width columns
Create equal-width columns by assigning table-equal-cols to the outputclass attribute for the <table> element.
| Name | Value |
|---|---|
| Mike | Awesome |
| Other | OK |
Column width specifications
Be default, browsers apply their own algorithms to evaluate table content, and then attempt to automatically size the columns appropriately. You can provide guidance or specificity to the browser using DITA column-width specifiers.
For example, consider this table:
| Alpha | Beta | Delta |
|---|---|---|
| This and the next column are the same width. | This and the previous column are the same width. | This column is twice a wide as each of the previous two columns. |
The widths are assigned to each colum as a proportion of the entire table width using the colwidth attribute in the table source code. This specification says the table width can be dived into 4 equal portions (1+1+2), and the first two columns each get one portion (1*) while the third column gets two portions (2*).
…
<tgroup cols="3">
<colspec colname="c1" colnum="1" colwidth="1*"/>
<colspec colname="c2" colnum="2" colwidth="1*"/>
<colspec colname="c3" colnum="3" colwidth="2*"/>
<thead>
…
When using proporttionals widths, assign the attribute to all columns or you will get undesirable results.
| Alpha | Beta | Delta |
|---|---|---|
| This column has no sizing. | This column has no sizing but it has more text, which usually forces the browser to allocate more width to it. | This column is assigned one proportion of the table's width. |
The colwidth specifcation looks like this:
…
<tgroup cols="3">
<colspec colname="c1" colnum="1" />
<colspec colname="c2" colnum="2" />
<colspec colname="c3" colnum="3" colwidth="1*"/>
<thead>
…
The colwidth attribute can also accept fixed units (like inches, points, and pixels), which should be avoided except in the most extreme cases. When you do use it, use "rem" units, which are equal to the with of the capital letter 'M' in the base font for the page.
| Alpha | Beta | Delta |
|---|---|---|
| This column width is "15rem". | This column has no sizing. | This column has no sizing. It does, however, have a lot of text which should force the browser to allocaet space for it. |
The colwidth specifcation looks like this:
…
<tgroup cols="3">
<colspec colname="c1" colnum="1" colwidth="15rem"/>
<colspec colname="c2" colnum="2" />
<colspec colname="c3" colnum="3"/>
<thead>
…
"Double-entry" table
A "double-entry" table has heading across the top and down the first (left) column.
Assign th to the outputclass attribute for an <entry> cell, you can make it look like a heading.
| Skill 1 | Skill 2 | |
|---|---|---|
| Member 1 | X | |
| Member 2 | X | |
| Member 3 | X | X |
Simple Table
DITA has an element called a Simple Table (<simpletable>).
Wide table with horizontal scroll
The <table> is in a <p outputclass='table-h-scroll>, like this:
<p outputclass="table-h-scroll">
<table>
...
| Function | Description | Parameters | Output data type | Syntax | Example |
|---|---|---|---|---|---|
| DATE | Returns a date value from year, month, and day values you enter. | Year (YYYY), Month (MM), Day (DD) | Date | DATE(year, month, day) | DATE("2020", "01", "01") |
| DATEDIF | Calculates the number of days, months, or years between two dates. | Date, Date, Type | Integer | DATEDIF(date, date, type) | DATEDIF([Creation date] , [Response date], "D") |
| getUnitGroupDatafield | Retrieves a Unit group Data field value by descending through the levels of Unit group children from the starting node. Descending will stop once there are no more children or the maxDescendantLevel has been reached. If the given Unit belongs to more than one leaf unit group at the final level, an exception will be thrown because we cannot be sure which is the desired value. If there is more than one leaf, then the setup will need to change. Returns a string value of the one Unit Group Data field found or null if not. | getUnitGroupDatafield(unit, text, integer, text) | getUnitGroupDatafield([Account], 'b2b_region', 1, 'name') |
