2013-05-09 79 views
7

我想要一個包裹着文字的圖。如何在reStructuredText/Sphinx中創建浮動數字?

這是我在說什麼:

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.

  • 爲什麼圖題居中,而不是下的圖像?
  • 爲什麼不在圖像的左邊而不是在其下面的正文文本(「確定...」和「拿...」)?我希望這個數字能夠正確地浮動,並在左邊有文字。

回答

6

所以,我對reStructuredText做了一些研究,看起來你想要的東西實際上是不可能的。

figureimage指令的文檔從未提及在對象周圍換行的能力。

這可能是向Sphinx開發人員提供的功能請求,儘管我懷疑他們會拒絕它,因爲它在第一個規範中沒有明確提及。

我一直希望賞金能夠吸引一些注意,但我懷疑是沒有。

0

爲了處理圖像,因爲它們是文本的一部分,您可能實際使用substitutions

這裏從可以幫助文檔的摘錄:

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

.. |biohazard| image:: biohazard.png 

我希望這有助於

+0

計劃上市這不是很有益的,如果一個需要投入大量燈光字母在章節的開頭。 – Frotz 2016-04-07 01:43:22

1

如果別人運行到這個問題,那麼這段代碼可能是一個幫助。我決定我不想破解實際的獅身人面像代碼,所以我對生成的_build/latex/pi3d_book.tex應用了一個非常短的Python腳本,以便將之前或之後有\hfill\includegraphics轉換爲包裝圖像。將會有很多事情阻止這項工作,例如將圖像放入列表或縮放圖像。我的第一個獅身人面像指令就像

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

顯然,您必須更改文件名和路徑以適合您的設置。從我spinx項目中,我跑的wrapfix.py

import subprocess 

with open("_build/latex/pi3d_book.tex", "r") as f: 
    tx = f.read().splitlines() 

txnew = [] 
flg1 = True 
for line in tx: 
    if line == "" and flg1: 
    txnew += ["\\usepackage{wrapfig}",""] 
    flg1 = False # just do this once before first blank line 
    elif "includegraphics{" in line and "hfill" in line: 
    fname = line.split("{")[2].split("}")[0] 
    if line.startswith("{\\hfill"): # i.e. right justify 
     fl_type = "R" 
    else: 
     fl_type = "L" 
    txnew += ["\\begin{wrapfigure}{" + fl_type + "}{0.35\\textwidth}", 
       "\\includegraphics[width = 0.3\\textwidth]{" + fname + "}", 
       "\\end{wrapfigure}"] 
    else: 
    txnew += [line] 

txnew = "\n".join(txnew) 
with open("_build/latex/pi3d_book.tex", "w") as fo: 
    fo.write(txnew) 

subprocess.Popen(["pdflatex", "pi3d_book"], cwd="/home/jill/pi3d_book/_build/latex")