Sphinx toctree directive: How to hide the caption from being displayed?
Asked Answered
A

2

6

If I have the following in index.rst:

This Section
------------

.. toctree::
   :caption: This Section
   :maxdepth: 1

   this_section/intro
   this_section/body
   this_section/outro

Then "This Section" would show up twice in the generated HTML file: One as a <h1>, one as a <p class="caption">. How can I get rid of the latter, or make :caption: generate a <h1>? I can't simply remove :caption: because the sidebar (I'm using ReadTheDoc theme) relies on this option to correctly generate a TOC tree.

Augustusaugy answered 29/6, 2021 at 19:45 Comment(1)
Did you find a satisfactory solution/workaround to this?Dulcinea
F
2

My workaround is to hide the original toctree and link again to contents...

This section
------------

* :doc:`intro <this_section/intro>`
* :doc:`body <this_section/body>`

.. toctree::
   :caption: This Section
   :hidden:

   this_section/intro
   this_section/body
   this_section/outro

Folly answered 13/10, 2021 at 19:45 Comment(1)
both answers work well, but I believe this one should be the accepted oneMidrash
D
2

I ended up removing this with css by adding this to custom.css in the _static directory:

section#setup span.caption-text {
    display: none;
}

And having this in my conf.py:

html_static_path = ['_static']
html_css_files = ['custom.css']
Dulcinea answered 8/2, 2022 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.