How can I place images side-by-side in restructured text?
Asked Answered
G

6

26

Is there a way to put 2 different images on the same "line", so, side-by side?

I know there is the :align: option, but if I put two images, the first with :align: left and the second with :align: right it doesn't work, because the latter is put in another paragraph.

Gleeful answered 3/3, 2014 at 14:45 Comment(0)
S
-6

Try this:

.. class:: center

This text is centered
Senghor answered 3/3, 2014 at 14:50 Comment(1)
It doesn't work for me. Can you explain a bit further how this works? That .. class:: center goes before both .. image::s?Metalworking
W
40

I used substitution definitions:

|pic1| any text |pic2|

.. |pic1| image:: img1.png
   :width: 45%

.. |pic2| image:: img2.png
   :width: 45%
Wiebmer answered 1/3, 2017 at 2:19 Comment(1)
The blank newlines in the above answer have to be there. Just tried it without those and it doesn't give the expected output.Zn
A
15
.. list-table:: 

    * - .. figure:: ../_static/1repren.png

           Fig 1. Representations

      - .. figure:: ../_static/5transparency.png

           Fig 2. Transparency
    * - .. figure:: ../_static/9ele.png

           Fig 3. Electrostatics

      - .. figure:: ../_static/11R3D.PNG.png

           Fig 4. R3D
Agha answered 14/6, 2019 at 8:45 Comment(0)
G
9

You want the images to be part of the same paragraph and you want them to split the width of the screen so do something like this:

.. image:: im1.jpg
    :width: 50 %
.. image:: im2.jpg
    :width: 50 %

This doesn't exactly work, there will be some spacing between the 2 images which will put the total width >100%. A simple workaround is setting the widths to 49%. Doing so, below is the output with the unformatted image above to compare: RenderedImages

More reading: reST docs on Images

Gabriel answered 13/7, 2016 at 18:31 Comment(0)
C
1

To make this snippet (mentioned above by @fiona) work you need to declare | pic | before referencing it.

.. |pic1| image:: img1.png
   :width: 45%

.. |pic2| image:: img2.png
   :width: 45%

|pic1| any text |pic2|
Cerise answered 9/7, 2021 at 11:13 Comment(1)
No, you don't need to declare pic1 and pic2 before using them. The other answer is fine.Maharaja
M
0

The :align: option lets the subsequent content flow around the image. Using it for two images side-by-side is possible but a bit unintuitive.

Change the order of the images in the source: define the second image first and align it to the right. The following element will flow up to the left of this image (if there is enough space).

.. image:: img2.png
   :width: 45%
   :align: right
   
.. image:: img1.png
   :width: 45%

A list-table can be used, too

.. list-table::
   :width: 100%
   :class: borderless

   * - .. image:: img1.png
          :width: 100%
         
     - .. image:: img2.png
          :width: 100%

this can be easily expanded into a "picture grid".

Mackinaw answered 2/2 at 10:45 Comment(0)
S
-6

Try this:

.. class:: center

This text is centered
Senghor answered 3/3, 2014 at 14:50 Comment(1)
It doesn't work for me. Can you explain a bit further how this works? That .. class:: center goes before both .. image::s?Metalworking

© 2022 - 2024 — McMap. All rights reserved.