【问题标题】:How do we embed images in sphinx docs?我们如何在 sphinx 文档中嵌入图像?
【发布时间】:2014-09-16 10:14:48
【问题描述】:

我对使用 sphinx 很陌生,第一次为 python 项目做文档。 如何在 sphinx 文档中嵌入图像?

【问题讨论】:

    标签: python-sphinx


    【解决方案1】:

    来自documenation

    有两个图像指令:imagefigure

    image 是一张简单的图片。

    figure 由图像数据(包括图像选项)、可选标题(单个段落)和可选图例(任意正文元素)组成。对于基于页面的输出媒体,如果这有助于页面布局,数字可能会浮动到不同的位置。

    image 用法示例:

    .. image:: picture.jpg
       :width: 200px
       :height: 100px
       :scale: 50 %
       :alt: alternate text
       :align: right
    

    figure 用法示例:

    .. figure:: picture.png
       :scale: 50 %
       :alt: map to buried treasure
    
       This is the caption of the figure (a simple paragraph).
    

    【讨论】:

      【解决方案2】:

      使用image 指令,例如:

      .. image:: example.png
      

      图像的路径是相对于文件的。请参阅Sphinx documentation 了解更多信息。

      【讨论】:

      • 我也可以推荐尝试.. figure:: 指令,因为它有一些不错的功能。
      【解决方案3】:

      如果有人希望包含 inline 图像,则可以使用以下方法:

      The |biohazard| symbol must be used on containers used to dispose of medical waste.
      
      .. |biohazard| image:: biohazard.png
      

      (来自https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#substitution-definitions

      【讨论】:

        猜你喜欢
        • 2018-02-26
        • 2012-06-16
        • 1970-01-01
        • 2021-05-22
        • 2016-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-04
        相关资源
        最近更新 更多