Tables

Grid tables

Tables For grid tables (ref), you have to “paint” the cell grid yourself. They look like this:

Rst:

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | ...        | ...      |          |
+------------------------+------------+----------+----------+

Rendered Output:

Header row, column 1 (header rows optional)

Header 2

Header 3

Header 4

body row 1, column 1

column 2

column 3

column 4

body row 2

It can be styled by adding rst-class directive. Availbale options are ‘docs-table-green’, ‘docs-table-grey’, ‘highlight-head-X-green’ (replace X with 1-5 to highlight the corresponding header), ‘highlight-column-X-green’ (replace X with 1-5 to highlight the corresponding column), ‘docs-rotated-heading-table’

Rst:

.. rst-class:: docs-table-green

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | ...        | ...      |          |
+------------------------+------------+----------+----------+

Rendered Output:

Header row, column 1 (header rows optional)

Header 2

Header 3

Header 4

body row 1, column 1

column 2

column 3

column 4

body row 2

Simple tables

Simple tables (ref) are easier to write, but limited: they must contain more than one row, and the first column cells cannot contain multiple lines. They look like this:

Rst:

=====  =====  =======
A      B      A and B
=====  =====  =======
False  False  False
True   False  False
False  True   False
True   True   True
=====  =====  =======

Rendered Output:

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

It can be styled by adding rst-class directive. Availbale options are ‘docs-table-green’, ‘docs-table-grey’, ‘highlight-head-X-green’ (replace X with 1-5 to highlight the corresponding header), ‘highlight-column-X-green’ (replace X with 1-5 to highlight the corresponding column), ‘docs-rotated-heading-table’

Rst:

.. rst-class:: docs-table-green

=====  =====  =======
A      B      A and B
=====  =====  =======
False  False  False
True   False  False
False  True   False
True   True   True
=====  =====  =======

Rendered Output:

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

Rst:

.. rst-class:: docs-table-grey

=====  =====  =======
A      B      A and B
=====  =====  =======
False  False  False
True   False  False
False  True   False
True   True   True
=====  =====  =======

Rendered Output:

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

Rst:

.. rst-class:: docs-table-grey highlight-head-2-green highlight-column-2-green

 =====  =====  =======
 A      B      A and B
 =====  =====  =======
 False  False  False
 True   False  False
 False  True   False
 True   True   True
 =====  =====  =======

Rendered Output:

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

Rst:

.. rst-class:: docs-rotated-heading-table

 =====  =====  =======
 A      B      A and B
 =====  =====  =======
 False  False  False
 True   False  False
 False  True   False
 True   True   True
 =====  =====  =======

Rendered Output:

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

Two more syntaxes are supported: CSV tables and List tables. They use an explicit markup block. Refer to Tables for more information.

List tables

You can add reStructured Text table syntax with .. list-table:: directive.

Each table has the number of columns and their associated relative widths indicated in a width tag.

For proper formatting, the asterisk indicating each row must align vertically, and the hyphens indicating each column must also align. Empty cells must be accounted for, so that each column in a row is always marked, even if there is no content in the table cell. An example of an empty cell is the second column in the first row of the following example.

Rst:

.. list-table:: Title
 :widths: 25 25 50
 :header-rows: 1

 * - Heading row 1, column 1
   - Heading row 1, column 2
   - Heading row 1, column 3
 * - Row 1, column 1
   -
   - Row 1, column 3
 * - Row 2, column 1
   - Row 2, column 2
   - Row 2, column 3

Rendered Output:

Title

Heading row 1, column 1

Heading row 1, column 2

Heading row 1, column 3

Row 1, column 1

Row 1, column 3

Row 2, column 1

Row 2, column 2

Row 2, column 3

It can be styled by adding class option. Availbale options are ‘docs-table-green’, ‘docs-table-grey’, ‘highlight-head-X-green’ (replace X with 1-5 to highlight the corresponding header), ‘highlight-column-X-green’ (replace X with 1-5 to highlight the corresponding colum), ‘docs-rotated-heading-table’

.. list-table:: Title
 :widths: 25 25 50
 :header-rows: 1
 :class: docs-table-grey

 * - Heading row 1, column 1
   - Heading row 1, column 2
   - Heading row 1, column 3
 * - Row 1, column 1
   -
   - Row 1, column 3
 * - Row 2, column 1
   - Row 2, column 2
   - Row 2, column 3

Rendered Output:

Title

Heading row 1, column 1

Heading row 1, column 2

Heading row 1, column 3

Row 1, column 1

Row 1, column 3

Row 2, column 1

Row 2, column 2

Row 2, column 3