2017-05-29 11 views
2

reStructuredTextテンプレートをセットアップしようとしています。私は、番号の付いた数字とそれらへの言及を含める。だから、私はスフィンクスの文書(http://www.sphinx-doc.org/en/stable/markup/inline.html)で与えられた指示に従った。reStructuredText内のFigure Figure Numbers:

まず私は、ファイル 'conf.py' で

numfig = True 

行が含まれています。私は、ファイル内の図とそれへの参照を実装している「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` 

私はindex.htmlファイル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ファイルは、次に示してビルドするときここに示すように、図、キャプション、および参照先: output index.html

キャプションは、 1 'であるが、:numref:を使用している参照は明らかに機能しません。私も試しました

:numref:`my-figure` 

同様の結果につながった。

参照がここではうまくいかない理由を知っている人はいますか?

興味深いことに:上記のファイルはすべて、 'index.rst'ファイルに含まれている 'rstTemplate.rst'ファイルの.. include:: rstTemplate.rstにあります。 htmlビルドの後、私はファイル 'index.html'と 'rstTemplate.html'を受け取ります。 'index.html'バージョンとは異なり、 'Fig。 1 'は' rstTemplate.html 'の図のキャプションには含まれていません。ここで間違っていることに関連するかもしれませんか?

ありがとうございます。

+1

重複したラベルの警告を最初に解決してから、未定義のラベルの警告が続くかどうかを確認することをおすすめします。 –

答えて

0

には、次のものが含まれています

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ファイルにこの章をどのように組み込んだのかと思います。 MAXDEPTH:2 :キャプション:ホーム :隠された: rstTemplate' NUMREFは '..含ま:: rstTemplate.rst' しかし ' .. toctree :: を使用して動作しませんでした – 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:ラベルの代わりにfigureディレクティブに:name: my-figureオプションを使用することができます。

について:

私も同様の結果につながった

:numref:`my-figure` 

を試してみました。

私は再生できません。それは私のために大丈夫動作します。より広範な構文

上記の形式をカスタマイズするには、ここではかっこを追加する必要があります。あなたのconf.pyを想定し

関連する問題