pythonpython-sphinxsidebarsectionstoctree

Section titles in the Sphinx sidebar


Is there any way to add section titles in the left menu of Sphinx documentation? I know you can do it if you use MkDocs (for example here), but is there a way to do this in Sphinx and ReSTructured text?

I want to divide my documentation into separate sections (e.g. Installation instructions, Running the program, etc.), with the titles of those sections appearing as text in the left menu.


Solution

  • Finally figured out how you can do it in Sphinx...

    There is a :caption: directive that allows you to add a caption to the table of contents. For example, the table of contents for readthedocs looks like this:

    .. toctree::
       :maxdepth: 2
       :caption: User Documentation # <-- This is what I was looking for
    
       getting_started
       versions
       [...]
    

    The :caption: User Documentation adds the "User Documentation" section header to the sidebar:

    enter image description here

    I don't know why there is all that wite-space after the caption, but I guess it's just an issue with the theme...