【问题标题】:How to reset numbered sections in Sphinx?如何重置 Sphinx 中的编号部分?
【发布时间】:2018-02-12 10:41:55
【问题描述】:

我有几个相互独立的文档:

index.rst
foo.rst
bar.rst
conf.py
Makefile

我想从index.rst 访问foo.rst,但我希望这两个子文档的编号从 1 开始。

index.rst 我有:

.. toctree::
   :maxdepth: 2
   :numbered:

   foo
   bar

但是,bar 将采用数字 2.,而有了这个 bar.rst,我将获得 2.1 Tomatoes

=====
Title
=====

Tomatoes
========

Cucumbers
=========

我想要这样的渲染:

1. Tomatoes
2. Cucumbers

这怎么可能?

【问题讨论】:

  • 但是“标题”部分呢?看起来你想忽略它。
  • 是的,没错。当你开始一篇文章时,这篇文章的标题不是1.。仅命名了本文档的第一部分。这里,第一部分是Tomatoes
  • 我不明白。 bar.rst 中的第一部分是Title
  • 在我的例子中,Title 是文档的标题。如果我删除它,文档将被命名为Tomatoes
  • 重置节编号的唯一方法(我能想到的)是使用第二个toctree

标签: python-sphinx sections toctree


【解决方案1】:

你不能同时拥有它。有关说明,请参阅 Section numbering under the toctree directive 的 Sphinx 文档:

章节编号

如果您希望在 HTML 输出中也有部分编号,请为 toplevel toctree 提供编号选项。例如:

.. toctree::
  :numbered:

  foo
  bar

然后从foo 的标题开始编号。子目录会自动编号(不要给那些编号的标志)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 2013-12-02
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多