添加到@SuperKogito 的答案。如果您希望您的 TOC 支持不同的深度级别,同时仍然看起来很完整,您可以通过 CSS 来实现。
例如,给定以下部分
Contents # this will create a <div id="contents>...</>
========
.. toctree::
:maxdepth: 1
documents/Markdown1
.. toctree::
:maxdepth: 2
documents/Markdown2
在您的conf.py
, 在底部,添加以下行
def setup(app):
app.add_css_file('styles.css')
现在在您的 _static 文件夹(与您的文件夹级别相同conf.py
)中,添加一个名为styles.css
以下行的文件
// this selects the contents section, the first table of contents and the list item
// underneath it. Then it removes the spacing to make it look whole. If you have more
// items, you can consider using :not(:last-of-type) selector.
#contents .toctree-wrapper:first-of-type ul {
margin-bottom: 0;
}