我在使用Sphinx上是比较新的,第一次为Python项目做文档。 如何在Sphinx文档中嵌入图片?
我在使用Sphinx上是比较新的,第一次为Python项目做文档。 如何在Sphinx文档中嵌入图片?
根据文档:
有两种图像指令:
image
和figure
。一个
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).
如果有人想要添加一个内联图片,以下内容可以实现:
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)
|生物危害|
)就可以在同一文档页面内轻松重复使用。 - jeannej确保在上面这行话之间有一行空白,该行话是 .. image::
我的图片没有显示出来,但我只需要把它与上面的文字分开就好了。
由于您必须使用相对路径,因此我创建了一个名为images
的目录,在这种情况下,我需要使用以下图像路径:
.. image:: ..\\images\\image.png