如何在reStructuredText / Sphinx中创建浮动数字?

时间:2013-05-09 13:32:28

标签: python-sphinx restructuredtext

我想要一个带有文字的图形。

这就是我所说的:

Installation of Optional Accessories
====================================

.. warning:: Never plug in or unplug a Hand Robot or a Grasp Sensor while the robot is turned on, as the system will not function properly and damage to the robot could occur.

Installing a Hand Robot
-----------------------

.. _`fig-attach-hand-robot`:
.. figure:: attach-hand-robot.*
  :scale: 40%
  :align: right

  Attach Hand Robot

Make sure the robot is turned off as described in the section :ref:`turn-off-robot`. 

Take the hand robot out of the grounded bin that sits on top of the electrical panel (if you have an adjustable height table) or sits on top of the rear table (if you have a fixed height table). Make sure not to touch the pins on the electrical wiring while doing so. Insert the conical protrusion of the hand robot into the conical receptacle (see :ref:`fig-attach-hand-robot`). Once the hand robot is supported by the InMotion Arm Robot, make sure the two knobs below the Hand Robot have engaged and sprung in. If they have not, twist them until they do as shown (see :ref:`fig-knobs-in`).


this screenshot of PDF output is what I'm getting.

  • 为什么数字标题居中,而不是在图像下?
  • 为什么身体文字(“确保......”和“拿......”)不在图像的左侧,而不是在它下面?我希望图形向右浮动,并在左侧显示文字。

5 个答案:

答案 0 :(得分:6)

所以,我对reStructuredText进行了一些研究,看起来你想要的实际上是不可能的。

figureimage指令的文档从未提及在对象周围包装文本的功能。

这可能是向Sphinx开发人员提供的功能请求,尽管我怀疑他们会拒绝它,因为在第一个规范中没有明确提到它。

我希望赏金会引起一些关注,但我怀疑是没有。

答案 1 :(得分:2)

虽然为时已晚,但也许答案会对将来的人们有所帮助。

您可以使用侧边栏指令放置图像。

.. sidebar:: mandatory_title. Use can use image caption here

     .. Figure:: 1.png

答案 2 :(得分:1)

为了处理图片,因为它们是文本的一部分,您可能实际使用substitutions

这里是文档中可能有用的摘录:

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

.. |biohazard| image:: biohazard.png

我希望这会有所帮助

答案 3 :(得分:1)

如果其他人遇到此问题,那么这段代码可能是一个帮助。我决定我不想破解实际的sphinx代码,所以我将一个非常短的python脚本应用于生成的_build/latex/pi3d_book.tex以转换之前有\includegraphics的{​​{1}}或进入包装图像后。将有许多东西阻止这种工作,例如将图像放入列表或缩放图像。我的rst中的sphinx指令就像

\hfill

您显然必须更改文件名和路径以适合您的设置。从我的spinx项目中我运行

.. image:: perspective.png
   :align: right

$ make latexpdf $ python wrapfix.py # or whatever you call this file

的程序列表
wrapfix.py

答案 4 :(得分:1)

我发现数字浮动到指定了:figwidth::align:的一侧。 (使用readthedocs主题。)

..  figure:: images/myimage.jpg
    :figwidth: 40%
    :align: right

https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure