如何在Sphinx中正确地使用numref表?

Dou*_*tti 3 python python-sphinx

我试图在Sphinx文档中引用一个表格.我为表命名,然后尝试使用numref,但它错误地显示了表的标签("modules_classes")而不是它的编号.

.. _modules_classes:

.. table:: Modules and their corresponding abstract classes

[table content]

Modules and their corresponding abstract classes are presented on table :numref:`modules_classes`.
Run Code Online (Sandbox Code Playgroud)

我也试过这样做,因为我在网上找到了一个例子,但结果是一样的:

.. table:: Modules and their corresponding abstract classes
    :name: modules_classes
Run Code Online (Sandbox Code Playgroud)

我看到它的方式,我不需要导入numfig包,因为它默认包含在Sphinx中.使用该命令:ref:显示表的标题,所以我理解引用是正确的.有人能指出我所做的事情有什么不对吗?

mzj*_*zjn 7

补救措施是numfig = True在conf.py中设置.如果没有此设置,您应该在运行sphinx-build时看到一条消息,其中显示"警告:numfig已禁用.:numref:被忽略".

这适用于HTML和LaTeX输出.请参见http://sphinx-doc.org/en/stable/config.html#confval-numfig.

  • 我正在使用以不同方式编译LaTeX和HTML文档的解决方法.从那时起,我放弃了这种方法,并且使用相同的源`rst`文件生成文档的两个版本,表编号在两者中都是正确的. (2认同)