Referencing figures with numbers in Sphinx and reStructuredText

In the latest versions of Sphinx (1.3+), numbering figures and referencing them from text got a bit easier as support for it is now built-in.

In your text, you can do something like:

.. _label:
.. figure:: images/figure.*


At :numref:`label` you can see...

The end result should be something like “At Fig 1.1 you can see…”. This technique works both with the default HTML output and the LaTeX output.

In your conf.py file, make sure to set the flag numfig = True. There are also configuration options for the references’ text format (numfig_format and numfig_secnum_depth).

References:

  • http://www.sphinx-doc.org/en/stable/config.html#confval-numfig
  • https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#cross-referencing-figures-by-figure-number

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)