2017-05-29 50 views
2

目前我正在試圖安裝一個新結構化模板。我想包括編號的數字和參考。所以我也跟着獅身人面像文檔(http://www.sphinx-doc.org/en/stable/markup/inline.html)中的說明。參考圖

首先我包括線

numfig = True 
在文件 'conf.py'

。我實現了這個數字,在我的文件「rstTemplate.rst」對它的引用如下:

.. _my-figure: 

.. figure:: images/scen-smartcity.* 
    :scale: 50 % 
    :alt: smartcity symbol 
    :align: center 

    This is the caption of the figure (a simple paragraph). 

    This is the legend of the figure 

Reference to the figure :numref:`(Fig. %s) my-figure` 

當我建立使用make html

Running Sphinx v1.6.1 
loading pickled environment... done 
building [mo]: targets for 0 po files that are out of date 
building [html]: targets for 1 source files that are out of date 
updating environment: 0 added, 2 changed, 0 removed 
reading sources... [100%] rstTemplate 
rstTemplate.rst:: WARNING: duplicate label my-figure, other instance in ><path-to-file>\rstTemplate.rst 
<path-to-file>\rstTemplate.rst:: WARNING: duplicate label my-figure, other instance in <path-to-file>\index.rst 
looking for now-outdated files... none found 
pickling environment... done 
checking consistency... done 
preparing documents... done 
writing output... [100%] rstTemplate 
rstTemplate.rst:41: WARNING: undefined label: (fig. %s) my-figure 
<path-to-file>\rstTemplate.rst:41: WARNING: undefined label: (fig. %s) my-figure 
generating indices... genindex 
writing additional pages... search 
copying images... [100%] images/scen-smartcity.svg 
copying static files... done 
copying extra files... done 
dumping search index in English (code: en) ... done 
dumping object inventory... done 
build succeeded, 6 warnings. 

HTML文件中的index.html文件則顯示圖中,標題和引用如下所示: output index.html

因此,標題顯示一個不錯的'圖。 1「,但使用:numref:的參考顯然不起作用。我也試過

:numref:`my-figure` 

這導致了類似的結果。

有誰知道爲什麼引用不在這裏工作了?

還有什麼值得注意的:上述所有內容都在我的文件'rstTemplate.rst'中,我通過.. include:: rstTemplate.rst將它包含在文件'index.rst'中。在構建html之後,我收到文件'index.html'和'rstTemplate.html'。與'index.html'版本不同,'Fig。 1'不包含在'rstTemplate.html'圖中的標題中。可能與這裏出了什麼問題有關?

在此先感謝。

+1

我建議先解決重複標籤警告,然後看看未定義的標籤警告是否持續。 –

回答

0

假設你conf.py包含以下內容:

import sys 
import os 
html_theme = 'sphinx_rtd_theme' 
numfig = True 

和你index.rst包含:

.. toctree:: 
    :maxdepth: 2 
    :caption: Home 
    :hidden: 

mychapter 

這裏是一章RST文件mychapter.rst工作示例:

.. figure:: images/my-image.png 
    :name: my-custom-label 

This is a caption of the image 

This is a reference to :numref:`my-custom-label` bla bla ... 

這呈現爲:

This is a reference to Fig.1 bla bla ... 
+1

謝謝你viliam,這工作。我認爲這就是我如何將該章節包含在index.rst文件中的方式。該numref沒有與 工作'..包括:: rstTemplate.rst' 但使用 '.. toctree :: 時:MAXDEPTH:2 :標題:首頁 :隱藏: rstTemplate' – stackholder

0

截至http://www.sphinx-doc.org/en/stable/markup/inline.html?highlight=numfig#role-numref

獨立句話解釋你應該使用下面的語法

Reference to the figure :numref:`(Fig. %s) <my-figure>` 

:您可以代替.. _my-figure:標籤的使用:name: my-figure選項將figure指令。

關於:

我也試過

:numref:`my-figure` 

導致類似的結果。

我無法重現。它適合我。更廣泛的語法

:numref:`(Fig. %s) <my-figure>` 

上面只需要定製格式,這意味着在這裏添加括號。