Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we embed images in sphinx docs?

I am quite new in using sphinx, Doing documentation for the first time for the python project. How to embed image for example in the sphinx documentation ?

like image 952
Ciasto piekarz Avatar asked Sep 16 '14 10:09

Ciasto piekarz


People also ask

What is Sphinx read the docs?

Sphinx is a powerful documentation generator that has many great features for writing technical documentation including: Generate web pages, printable PDFs, documents for e-readers (ePub), and more all from the same sources. You can use reStructuredText or Markdown to write documentation.


4 Answers

From the documenation:

There are two image directives: image and figure.

An image is a simple picture.

A figure consists of image data (including image options), an optional caption (a single paragraph), and an optional legend (arbitrary body elements). For page-based output media, figures might float to a different position if this helps the page layout.

Example for image usage:

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

Example for figure usage:

.. figure:: picture.png
   :scale: 50 %
   :alt: map to buried treasure

   This is the caption of the figure (a simple paragraph).
like image 109
Jacek Krawczyk Avatar answered Oct 17 '22 09:10

Jacek Krawczyk


Use the image directive, for example:

.. image:: example.png

The path to the image is relative to the file. See the Sphinx documentation for more information.

like image 37
devin_s Avatar answered Oct 17 '22 11:10

devin_s


In case anyone is looking to include an inline image, the following works:

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

.. |biohazard| image:: biohazard.png

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

like image 17
Ken Avatar answered Oct 17 '22 10:10

Ken


Make sure there is a line between above the line that says .. image::

My image wasn't showing, but I just had to separate it from the text line that was above it.

like image 1
loftusmi3 Avatar answered Oct 17 '22 09:10

loftusmi3