如何在重组文本中并排放置图像?

问题描述 投票:0回答:6

有没有办法将两个不同的图像并排放在同一条“线”上?

我知道有

:align:
选项,但是如果我放置两个图像,第一个带有
:align: left
,第二个带有
:align: right
,则不起作用,因为后者放在另一个段落中。

restructuredtext text-alignment
6个回答
40
投票

我使用了替换定义

|pic1| any text |pic2|

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

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

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

9
投票

您希望图像成为同一段落的一部分,并且希望它们分割屏幕的宽度,因此请执行以下操作:

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

这并不完全有效,两个图像之间会有一些间距,这将使总宽度> 100%。一个简单的解决方法是将宽度设置为 49%。这样做,下面是与上面未格式化图像的输出进行比较: RenderedImages

更多阅读:图像上的reST文档


1
投票

要使此代码片段(@fiona 上面提到的)工作,您需要声明 |图片|在引用它之前。

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

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

|pic1| any text |pic2|

0
投票

:align: 选项让后续内容围绕图像流动。 将它并排用于两个图像是可能的,但有点不直观。

更改源中图像的顺序:首先定义第二个图像并将其向右对齐。以下元素将向上流动到该图像的左侧(如果有足够的空间)。

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

也可以使用列表

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

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

这可以轻松扩展为“图片网格”。


-6
投票

试试这个:

.. class:: center

This text is centered
© www.soinside.com 2019 - 2024. All rights reserved.