pythonpython-sphinxhorizontal-linetoctree

Can I add a horizontal bar to a table of contents in Sphinx?


I'm developing documentation in Sphinx, and would like to separate sections in my table of contents using horizontal bars.

I often see this in menus:

enter image description here

Is there a way to do it in sphinx?


Solution

  • The python sphinx .. toctree:: directive doesn't allow much variation besides the documents you include in the directive body, plus a few directive options.

    What I've seen others do in this case is splitting one toctree into several, including reStructuredText in between them.

    You could use an alternative to the toctree. Quoting the documentation:

    Note

    For local tables of contents, use the standard reST contents directive.

    The easiest way is splitting the menu into several toctrees including a HTML horizontal ruler between them:

    Sphinx_test
    ===========
    
    
    .. toctree::
       :maxdepth: 4
       
       undo
       redo
    
    .. raw:: html
    
       <hr>
    
    .. toctree::
       :maxdepth: 4
       
       cut
       copy
    
    .. raw:: html
    
       <hr>
       
    .. toctree::
       :maxdepth: 4
          
       find
       Speech
    

    And the result:

    enter image description here