Skip to main content

reStructuredText provides four syntaxes for tables:

  • Grid tables

  • Simple tables

  • List tables

  • CSV tables

However, only grid and simple tables support cells spanning multiple columns, and only grid tables support cells spanning multiple rows.

The rst-table-span package adds the :colspan:`C`, :rowspan:`R`, and :cellspan:`CxR` roles which add support for column and row span to all existing RST table types.

This project was inspired by the flat-table directive from the LinuxDoc project.

Example

To produce a table like this:

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

Cells may span columns.

body row 3

Cells may span rows.

Corner

body row 4

You would normally need to write this:

+------------------------+------------+----------+----------+
| 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             | Cells may span columns.          |
+------------------------+------------+---------------------+
| body row 3             | Cells may  | Corner              |
+------------------------+ span rows. |                     |
| body row 4             |            |                     |
+------------------------+------------+---------------------+

But with rst-table-span you can instead write it using a csv-table:

.. csv-table::
   :header-rows: 1

   "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, :colspan:`3` Cells may span columns.
   body row 3, :rowspan:`2` Cells may span rows., :cellspan:`2x2` Corner
   body row 4

Or a list-table:

.. list-table::
   :header-rows: 1

   * - 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
     - :colspan:`3` Cells may span columns.
     -
     -
   * - body row 3
     - :rowspan:`2` Cells may span rows.
     - :cellspan:`2x2` Corner
     -
   * - body row 4
     -
     -
     -

Installation and Usage

Install the package using pip:

pip install rst-table-span

or add the rst-table-span package to your project or environment dependency list (eg. pyproject.toml, requirements.txt, or similar).

Sphinx

Also add the rst_table_span module to your list of extensions in your conf.py settings:

extensions = [
    "rst_table_span",
]

Docutils

Docutils doesn’t provide a declarative extension mechanism, as far as I know. If you invoke docutils programatically using its Publisher API, then a global function is provided to register the roles. Call it before setting up the publisher:

import sys
import docutils.__main__
import rst_table_span

rst_table_span.register_docutils_roles()
sys.exit(docutils.__main__.main())

For convenience, this package installs the above script as the rst-table-span-docutils executable. It behaves the same way as the standard docutils executable. It can then be used used like this:

rst-table-span-docutils demo.rst --output demo.html

License

This library is released under the MIT license (see the LICENSE file in the source code).

Metadata

Release files for rst-table-span 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rst-table-span 1.0.1
File Size Uploaded
rst_table_span-1.0.1.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rst-table-span 1.0.1
File Interpreter ABI Platform
rst_table_span-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.6 kB

Release files / rst_table_span-1.0.1.tar.gz

Download URL rst_table_span-1.0.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8d561f4c548f7603c8a276079a07e5301c3ec31ce39c0224d0b64b18b8b9d2ea
BLAKE2b-256 checksum
How to use checksums
23917a0e6c7d074b96ec311ee1835a2684fa765307a63293e729b7e4d59aac19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / rst_table_span-1.0.1-py2.py3-none-any.whl

Download URL rst_table_span-1.0.1-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
28e89f3f6666be0a4011e76f4421025f61788264de16f3609d50293224cd142a
BLAKE2b-256 checksum
How to use checksums
3389bdb06dcb5091b4cdf55502c6d2eceab214c095e86148cf2ea1c9a973e52e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page