Referencing figures with numbers in Sphinx and reStructuredText

前端 未结 5 1313
挽巷
挽巷 2020-12-14 06:43

When writing RST that will be processed with Sphinx, I can\'t get Sphinx LaTeX output to use figure numbers when referencing figures. For instance, this code:



        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 06:55

    To expand on the accepted answer, you can quickly get this set up as follows. Put the numfig.py file in your source directory. Then open conf.py and uncomment the line that says

    sys.path.insert(0, os.path.abspath('.'))
    

    Then add 'numfig' to the extensions list.

    To use in your rst document, first label your figure (e.g., fig-main):

    .. _fig-main:
    
    .. figure:: main.png
    
       This is the figure caption.
    

    Finally, you can reference its figure number using the :num: directive, like this:

    Refer to the main figure (Figure :num:`fig-main`).
    

提交回复
热议问题