10

I have a toctree in my index.rst that looks something like this:

.. toctree::
   :maxdepth: 2

   cat
   dog
   moose

I am looking to to nest the contents of my toctree similar to how it is done here with 'api documentation':

enter image description here

So ultimately make something like:

.. toctree::
   :maxdepth: 2
   :dropdown Animals
     cat
     dog
     moose

But I cannot seem to find anything that does this in the docs.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
ApathyBear
  • 9,057
  • 14
  • 56
  • 90

1 Answers1

21

This behaviour of the toctree in the sidebar is is a feature of the Read the Docs theme (https://github.com/snide/sphinx_rtd_theme)

Install it with pip install sphinx-rtd-theme

The theme has the option collapse_navigation that controls whether to auto-collapse the tree when navigating to another part of the documentation or not.

# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
html_theme_options = {
    "collapse_navigation" : False
}

indexr.rst:

#################
  Title
#################

Animals
=======

.. toctree::
   :maxdepth: 2

    animals/index

Flowers
=======

.. toctree::
   :maxdepth: 2

   flowers/index

animals/index.rst:

####################
  Animals
####################

.. toctree::
   :maxdepth: 2

   cat
   dog
   moose
yardstick17
  • 4,322
  • 1
  • 26
  • 33
P.G.
  • 623
  • 6
  • 13
  • 2
    Thanks for the answer, I think you mis-identified my problem though, I am wondering how to write the toctree rules to actually make a drop down similar to in the example. The `:dropdown Animals` command is incorrect. I want to set arbitrary group sections that drop down into real doc pages – ApathyBear Apr 29 '16 at 14:45
  • 1
    There's no support for alternate toctree behavior in this theme as I could not see any config options listed in the documentation. One could fork the theme itself and maintain custom code to solve this. https://sphinx-rtd-theme.readthedocs.io/en/latest/configuring.html – marknuzz Jul 24 '19 at 23:46