Table Cells

Cell formatting

In addition to sharing many of the column specifier capabilities, cell specifiers allow cells to span rows and columns. Like a column specifier, a cell specifier is made up of components. These components, listed and defined below, are all optional.

  • span

  • align

  • style

A cell specifier is prefixed directly to the cell delimiter (|) preceding the content you want to customize.

The span component can duplicate a cell or have it span multiple rows or columns.

Duplicate cell content

To duplicate a cell in multiple, consecutive columns, prefix the | with the multiplication factor and the * operator.

Cell duplicated across three columns
|===

|Cell in column 1, row 1 |Cell in column 2, row 1 |Cell in column 3, row 1

3*|Same cell content in columns 1, 2, and 3

|Cell in column 1, row 3
|Cell in column 2, row 3
|Cell in column 3, row 3

|===
Result: Rendered table where cell was duplicated across three columns

Cell in column 1, row 1

Cell in column 2, row 1

Cell in column 3, row 1

Same cell content in columns 1, 2, and 3

Same cell content in columns 1, 2, and 3

Same cell content in columns 1, 2, and 3

Cell in column 1, row 3

Cell in column 2, row 3

Cell in column 3, row 3

Span columns and rows

To have a cell span multiple, consecutive columns, prefix the | with the span factor and the + operator.

Cell spanning three columns
|===

|Cell in column 1, row 1 |Cell in column 2, row 1 |Cell in column 3, row 1

3+|Content in a single cell that spans columns 1, 2, and 3

|Cell in column 1, row 3
|Cell in column 2, row 3
|Cell in column 3, row 3

|===
Result: Rendered table where cell spans three columns

Cell in column 1, row 1

Cell in column 2, row 1

Cell in column 3, row 1

Content in a single cell that spans columns 1, 2, and 3

Cell in column 1, row 3

Cell in column 2, row 3

Cell in column 3, row 3

If you want to have a cell span multiple, consecutive rows, prefix the span factor with a dot (.).

Cell spanning two rows
|===

|Cell in column 1, row 1 |Cell in column 2, row 1 |Cell in column 3, row 1

.2+|Content in a single cell that spans rows 2 and 3
|Cell in column 2, row 2
|Cell in column 3, row 2

|Cell in column 2, row 3
|Cell in column 3, row 3

|===
Result: Rendered table where a cell spans two rows

Cell in column 1, row 1

Cell in column 2, row 1

Cell in column 3, row 1

Content in a single cell that spans rows 2 and 3

Cell in column 2, row 2

Cell in column 3, row 2

Cell in column 2, row 3

Cell in column 3, row 3

Of course you can combine spanning over columns and rows. The number before the dot (.) is the number of columns to span and the number after the dot (.) is the number of rows to span.

Cell spanning columns and rows
|===

|Column 1, row 1 |Column 2, row 1 |Column 3, row 1 |Column 4, row 1

|Column 1, row 2
2.3+|Content in a single cell that spans over rows and columns
|Column 4, row 2

|Column 1, row 3
|Column 4, row 3

|Column 1, row 4
|Column 4, row 4
|===
Result: Rendered table where a cell spans over columns and rows

Column 1, row 1

Column 2, row 1

Column 3, row 1

Column 4, row 1

Column 1, row 2

Content in a single cell that spans over rows and columns

Column 4, row 2

Column 1, row 3

Column 4, row 3

Column 1, row 4

Column 4, row 4

Align cell content

The alignment component for cells works the same as the column specifier alignment component.

Cells aligned horizontally, vertically, and across a span of three columns
[cols="3"]
|===
^|Prefix the `{vbar}` with `{caret}` to center content horizontally
<|Prefix the `{vbar}` with `<` to align the content to the left horizontally
>|Prefix the `{vbar}` with `>` to align the content to the right horizontally

.^|Prefix the `{vbar}` with a `.` and `{caret}` to center the content in the cell vertically
.<|Prefix the `{vbar}` with a `.` and `<` to align the content to the top of the cell
.>|Prefix the `{vbar}` with a `.` and `>` to align the content to the bottom of the cell

3+^.^|This content spans three columns (`3{plus}`) and is centered horizontally (`{caret}`) and vertically (`.{caret}`) within the cell.

|===
Result: Rendered cells aligned horizontally, vertically, and across a span of three columns

Prefix the | with ^ to center content horizontally

Prefix the | with < to align the content to the left horizontally

Prefix the | with > to align the content to the right horizontally

Prefix the | with a . and ^ to center the content in the cell vertically

Prefix the | with a . and < to align the content to the top of the cell

Prefix the | with a . and > to align the content to the bottom of the cell

This content spans three columns (3+) and is centered horizontally (^) and vertically (.^) within the cell.

To use a pipe (|) within the content of a cell without creating a new cell, you must use the {vbar} attribute.

Style cell content

The style component can also be applied to individual cells. For example, you can apply the AsciiDoc element styles to an individual cell by prefixing the vertical bar with an a.

Comparing cells using AsciiDoc styles and no AsciiDoc styles
[cols="2"]
|===

a|This cell is prefixed with an `a`, so the processor interpets the following lines as an AsciiDoc list.

* List item 1
* List item 2
* List item 3
|This cell *is not* prefixed with an `a`, so the processor does not interpret the following lines as an AsciiDoc list.

* List item 1
* List item 2
* List item 3

a|This cell is prefixed with an `a`, so the processor honors the `lead` style on the following paragraph.

[.lead]
I am a paragraph styled with the lead attribute.
|This cell *is not* prefixed with an `a`, so the processor does not honor the `lead` style on the following paragraph.

[.lead]
I am a paragraph styled with the lead attribute.
|===
Result: Rendered table comparing cells using AsciiDoc styles and no AsciiDoc styles

This cell is prefixed with an a, so the processor interpets the following lines as an AsciiDoc list.

  • List item 1

  • List item 2

  • List item 3

This cell is not prefixed with an a, so the processor does not interpret the following lines as an AsciiDoc list.

* List item 1 * List item 2 * List item 3

This cell is prefixed with an a, so the processor honors the lead style on the following paragraph.

I am a paragraph styled with the lead attribute.

This cell is not prefixed with an a, so the processor does not honor the lead style on the following paragraph.

[.lead] I am a paragraph styled with the lead attribute.

Source code listing can be placed inside cells by using the listing syntax.

Cells with source code listing
|===
|Source Code 1 |Source Code 2

a|
[source,python]
----
import os
print "%s" %(os.uname())
----

a|
[source,python]
----
import os
print ("%s" %(os.uname()))
----
|===
Result: Rendered table with cells containing source code listing
Source Code 1 Source Code 2
import os
print "%s" %(os.uname())
import os
print ("%s" %(os.uname()))

For the grand finale, let’s apply a variety of specifiers to individual cells.

Building a variety of cell specifiers
|===

2*>m|This content is duplicated across two columns.

It is aligned right horizontally.

And it is monospaced.

.3+^.>s|This cell spans 3 rows. The content is centered horizontally, aligned to the bottom of the cell, and strong.
e|This content is emphasized.

.^l|This content is aligned to the top of the cell and literal.

v|This cell contains a verse
that may one day expound on the
wonders of tables in an
epic sonnet.

|===
Result: Rendered table featuring a variety of cell specifiers

This content is duplicated across two columns.

It is aligned right horizontally.

And it is monospaced.

This content is duplicated across two columns.

It is aligned right horizontally.

And it is monospaced.

This cell spans 3 rows. The content is centered horizontally, aligned to the bottom of the cell, and strong.

This content is emphasized.

This content is aligned to the top of the cell and literal.
This cell contains a verse that may one day expound on the wonders of tables in an epic sonnet.