The AsciiDoc table syntax looks and behaves like other delimited block types and supports standard block configuration entries. Formatting is easy to read and, just as importantly, easy to enter.
AsciiDoc source.
[width="15%"] |======= |1 |2 |A |3 |4 |B |5 |6 |C |=======
Table 23.2. Columns formatted with strong, monospaced and emphasis styles
Columns 2 and 3 | ||
---|---|---|
footer 1 |
| footer 3 |
1 |
| Item 1 |
2 |
| Item 2 |
3 |
| Item 3 |
4 |
| Item 4 |
AsciiDoc source.
.An example table [width="50%",cols=">s,^m,e",frame="topbot",options="header,footer"] |========================== | 2+|Columns 2 and 3 |1 |Item 1 |Item 1 |2 |Item 2 |Item 2 |3 |Item 3 |Item 3 |4 |Item 4 |Item 4 |footer 1|footer 2|footer 3 |==========================
Table 23.3. Horizontal and vertical source data
Date | Duration | Avg HR | Notes |
---|---|---|---|
22-Aug-08 | 10:24 | 157 | Worked out MSHR (max sustainable heart rate) by going hard for this interval. |
22-Aug-08 | 23:03 | 152 | Back-to-back with previous interval. |
24-Aug-08 | 40:00 | 145 | Moderately hard interspersed with 3x 3min intervals (2min hard + 1min really hard taking the HR up to 160). |
Short cells can be entered horizontally, longer cells vertically. The default behavior is to strip leading and trailing blank lines within a cell. These characteristics aid readability and data entry.
AsciiDoc source.
.Windtrainer workouts [width="80%",cols="3,^2,^2,10",options="header"] |========================================================= |Date |Duration |Avg HR |Notes |22-Aug-08 |10:24 | 157 | Worked out MSHR (max sustainable heart rate) by going hard for this interval. |22-Aug-08 |23:03 | 152 | Back-to-back with previous interval. |24-Aug-08 |40:00 | 145 | Moderately hard interspersed with 3x 3min intervals (2min hard + 1min really hard taking the HR up to 160). |=========================================================
Table 23.4. A table with externally sourced CSV data
ID | Customer Name | Contact Name | Customer Address | Phone |
---|---|---|---|---|
AROUT | Around the Horn | Thomas Hardy | 120 Hanover Sq. London | (171) 555-7788 |
BERGS | Berglunds snabbkop | Christina Berglund | Berguvsvagen 8 Lulea | 0921-12 34 65 |
BLAUS | Blauer See Delikatessen | Hanna Moos | Forsterstr. 57 Mannheim | 0621-08460 |
BLONP | Blondel pere et fils | Frederique Citeaux | 24, place Kleber Strasbourg | 88.60.15.31 |
BOLID | Bolido Comidas preparadas | Martin Sommer | C/ Araquil, 67 Madrid | (91) 555 22 82 |
BONAP | Bon app' | Laurence Lebihan | 12, rue des Bouchers Marseille | 91.24.45.40 |
BOTTM | Bottom-Dollar Markets | Elizabeth Lincoln | 23 Tsawassen Blvd. Tsawassen | (604) 555-4729 |
BSBEV | B’s Beverages | Victoria Ashworth | Fauntleroy Circus London | (171) 555-1212 |
CACTU | Cactus Comidas para llevar | Patricio Simpson | Cerrito 333 Buenos Aires | (1) 135-5555 |
AsciiDoc source.
[format="csv",cols="^1,4*2",options="header"] |=================================================== ID,Customer Name,Contact Name,Customer Address,Phone include::customers.csv[] |===================================================
AsciiDoc source.
[cols="e,m,^,>s",width="25%"] |============================ |1 >s|2 |3 |4 ^|5 2.2+^.^|6 .3+<.>m|7 ^|8 |9 2+>|10 |============================
AsciiDoc table data can be psv, dsv or csv formatted. The default table format is psv.
AsciiDoc psv (Prefix Separated Values) and dsv (Delimiter Separated Values) formats are cell oriented — the table is treated as a sequence of cells — there are no explicit row separators.
:|\n
(a colon or a new line
character).
Here are four psv cells (the second item spans two columns; the last contains an escaped separator):
|One 2+|Two and three |A \| separator character
csv is the quasi-standard row oriented Comma Separated Values (CSV) format commonly used to import and export spreadsheet and database data.
Tables can be customized by the following attributes:
unfloat::[]
block macro to stop floating.
The cols attribute is a comma separated list of column specifiers. For example cols="2<p,2*,4p,>"
.
cols=4
.
Column specifiers define how columns are rendered and appear in the table cols attribute. A column specifier consists of an optional column multiplier followed by optional alignment, width and style values and is formatted like:
[<multiplier>*][<align>][<width>][<style>]
<align>
or <width>
is not important.
<width>
can be either an integer proportional value (1…)
or a percentage (1%…100%). The default value is 1. To ensure
portability across different backends, there is no provision for
absolute column widths (not to be confused with output column width
markup attributes which are available in both percentage and
absolute units).
The <align> column alignment specifier is formatted like:
[<horizontal>][.<vertical>]
Where <horizontal>
and <vertical>
are one of the following
characters: <
, ^
or >
which represent left, center and
right horizontal alignment or top, middle and bottom vertical
alignment respectively.
<multiplier>
can be used to specify repeated columns e.g.
cols="4*<"
specifies four left-justified columns. The default
multiplier value is 1.
<style>
name specifies a table style to used to markup
column cells (you can use the full style names if you wish but the
first letter is normally sufficient).
Cell specifiers allow individual cells in psv formatted tables to be
spanned, multiplied, aligned and styled. Cell specifiers prefix psv
|
delimiters and are formatted like:
[<span>*|+][<align>][<style>]
<span> specifies horizontal and vertical cell spans (+ operator) or the number of times the cell is replicated (* operator). <span> is formatted like:
[<colspan>][.<rowspan>]
Where <colspan>
and <rowspan>
are integers specifying the number of
columns and rows to span.
<align>
specifies horizontal and vertical cell alignment an is the
same as in column specifiers.
<style>
value is the first letter of table style name.
For example, the following psv formatted cell will span two columns and the text will be centered and emphasized:
`2+^e| Cell text`
Table styles can be applied to the entire table (by setting the style attribute in the table’s attribute list) or on a per column basis (by specifying the style in the table’s cols attribute). Table data can be formatted using the following predefined styles:
asciidoc(1)
as a filter to process cell contents. See also Docbook table limitations.
AsciiDoc makes a number of attributes available to table markup templates and tags. Column specific attributes are available when substituting the colspec cell data tags.
An alternative psv separator character ! can be used (instead of
|) in nested tables. This allows a single level of table nesting.
Columns containing nested tables must use the asciidoc style. An
example can be found in ./examples/website/newtables.txt
.
Fully implementing tables is not trivial, some DocBook toolchains do better than others. AsciiDoc HTML table outputs are rendered correctly in all the popular browsers — if your DocBook generated tables don’t look right compare them with the output generated by the AsciiDoc xhtml11 backend or try a different DocBook toolchain. Here is a list of things to be aware of:
Although nested tables are not legal in DocBook 4 the FOP and
dblatex toolchains will process them correctly. If you use a2x(1)
you will need to include the --no-xmllint
option to suppress
DocBook validation errors.
In theory you can nest DocBook 4 tables one level using the entrytbl element, but not all toolchains process entrytbl. |
a2x(1)
try the --no-xmllint
option, toolchains will often process nested block elements such as
sidebar blocks and floating titles correctly even though, strictly
speaking, they are not legal.