Different :maxdepth: for specific entries in toctree (Sphinx)
Asked Answered
B

1

12

I have some Sphinx based documentation for a library I built and I'd like to display the expanded table of contents for all my pages except for the changelog. I figured out how to do it by moving the changelog to a second :toctree::, but this has some strange behaviors. Mainly, the changelog shows up on a different bullet list when I visit the page, and when I use the sidebar navigation I can only navigate within each toctree (if I click on changelog, I won't have the other sections displayed on the sidebar). Is there a better way to do this?

Here's what I have right now:

.. toctree::
   :maxdepth: 5

   getting_started
   examples
   modules

.. toctree::
   :maxdepth: 1

   changelog


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Biogen answered 18/5, 2019 at 3:32 Comment(1)
It is not possible to have a different maxdepth for specific toctree items. Related question: https://mcmap.net/q/1012904/-sphinx-adds-headings-from-markdown-file-to-document-structure/407651.Ellaelladine
C
0

With the Read the Docs template you can achieve this. You further have to manipulate the style.css file in the _static directory. Simply add

.rst-content .toctree-wrapper:not(:last-child) ul {
   margin-bottom: 0;
}

and the two separate toc trees will look like one and they will be displayed in the side bar.

For other Sphinx templates an inspection of the rendered html could lead you into the right direction in finding the correct css-selector. But I don't know how these templates handle the sidebar.

Cinchonine answered 15/10, 2020 at 9:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.