Search code examples
python-sphinxrestructuredtext

break a long list into multiple columns in restructured text


Is there a way to break a long list into multiple columns in restructured text?

source:

* a
* b
* c
* d
* e
* a
* c
* a
* d
* e
* f

result:

* a   * e   * d
* b   * a   * e
* c   * c   * f
* d   * a

The goal is to provide the source list in a reST directive rather than using some other language to read the source list and then write the result text with the ".. raw::" directive in reST. Such as this hypothetical list-multicol directive:

.. list-multicol::
   :columns: 3

   * a
   * b
   * c
   * d
   * e
   * a
   * c
   * a
   * d
   * e
   * f

Extra credit for option to balance columns (same number of items +/- 1) no wider than the page or a specified number of columns.


Solution

  • Apparently, the hlist directive does this.

    http://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-hlist

    Here's the example:

    .. hlist::
       :columns: 3
    
       * A list of
       * short items
       * that should be
       * displayed
       * horizontally