Align figure center and bottom?

1,933 views
Skip to first unread message

Boris Kheyfets

unread,
Aug 20, 2012, 7:30:43 AM8/20/12
to sphin...@googlegroups.com
I have two figure in a table:

+----------------------------------------+-----------------------------------+
|.. _SuperCompArch:                      |.. _ClustArch:                     |
|                                        |                                   |
|.. figure:: _static/SuperCompArch.jpg   |.. figure:: _static/ClustArch.jpg  |
|   :width: 80%                          |   :width: 80%                     |
|   :alt: Supercomputer archeticture     |   :alt: Cluster archeticture      |
|   :align: center                       |   :align: center                  |
|                                        |                                   |
|   Super computer archeticture          |   Cluster archticture             |
+----------------------------------------+-----------------------------------+

but they are of different heigh. And I would like them to be sticked to the bottom of the table. In other words I want them to be centerd and bottomed in the same time.

I've read the docs, but it looks like `figure`  doesn't have `bottom` option at all.

Guenter Milde

unread,
Aug 23, 2012, 4:00:49 PM8/23/12
to sphin...@googlegroups.com
On 2012-08-20, Boris Kheyfets wrote:

> [-- Type: text/plain, Encoding: --]
There are two image directives: "image" and "figure".
If you don't need a caption and legend, use "image".

See http://docutils.sourceforge.net/docs/ref/rst/directives.html#images

There you also see:

align : "top", "middle", "bottom", "left", "center", or "right"
The alignment of the image, equivalent to the HTML <img> tag's
"align" attribute. The values "top", "middle", and "bottom" control
an image's vertical alignment (relative to the text baseline); they
are only useful for inline images (substitutions). The values "left",
"center", and "right" control an image's horizontal alignment,
allowing the image to float and have the text flow around it. The
specific behavior depends upon the browser or rendering software
used.

which means you need to define your images as inline, e.g. via

.. |left-image|
.. image:: _static/SuperCompArch.jpg
:width: 80%
:alt: Supercomputer archeticture
:align: bottom

and use the tag(s) in the table

=================== ================
|left-image| |right-image|

left caption right caption
=================== ================

Günter

Boris Kheyfets

unread,
Aug 27, 2012, 4:43:22 AM8/27/12
to sphin...@googlegroups.com
Thanks Gunter.

I tried:


+----------------------------------------+-----------------------------------+
|.. _SuperCompArch:                      |.. _ClustArch:                     |
|                                        |                                   |
|.. image:: _static/SuperCompArch.jpg    |.. image:: _static/ClustArch.jpg   |

|   :width: 80%                          |   :width: 80%                     |
|   :alt: Supercomputer archeticture     |   :alt: Cluster archeticture      |
|   :align: bottom                       |   :align: bottom                  |

|                                        |                                   |
|Super computer archeticture             |Cluster archticture                |
+----------------------------------------+-----------------------------------+

but it gives:

/home/boris/pst/wordy/edu/HighestProgramming/00_-_intro.rst:484: ERROR: Error in "image" directive: "bottom" is not a valid value for the "align" option.  Valid values for "align" are: "left", "center", "right".
/home/boris/pst/wordy/edu/HighestProgramming/00_-_intro.rst:484: ERROR: Error in "image" directive: "bottom" is not a valid value for the "align" option.  Valid values for "align" are: "left", "center", "right".

I'm using latest docutils (0.91) and Sphinx 1.1.3

Does the it work for You?

Any way it's a nice idea of "manual captions" -- I'm sure I'll use it somewhere.

Boris,

Guenter Milde

unread,
Aug 27, 2012, 9:40:43 AM8/27/12
to sphin...@googlegroups.com
On 2012-08-27, Boris Kheyfets wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> Thanks Gunter.

> I tried:

> +----------------------------------------+-----------------------------------+
>|.. _SuperCompArch: |..
> _ClustArch: |

>| |
>|.. image:: _static/SuperCompArch.jpg |.. image::
> _static/ClustArch.jpg |
>| :width: 80% | :width:
> 80% |
>| :alt: Supercomputer archeticture | :alt: Cluster
> archeticture |
>| :align: bottom | :align:
> bottom |

>| |
>|Super computer archeticture |Cluster
> archticture |
> +----------------------------------------+-----------------------------------+

> but it gives:

> /home/boris/pst/wordy/edu/HighestProgramming/00_-_intro.rst:484: ERROR:
> Error in "image" directive: "bottom" is not a valid value for the "align"
> option. Valid values for "align" are: "left", "center", "right".
> /home/boris/pst/wordy/edu/HighestProgramming/00_-_intro.rst:484: ERROR:
> Error in "image" directive: "bottom" is not a valid value for the "align"
> option. Valid values for "align" are: "left", "center", "right".

You still use block-level images.

>> which means you need to define your images as inline,

*outside of the table*, via a substitution definition
http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#substitution-definitions
e.g.

>> .. |left-image|
>> .. image:: _static/SuperCompArch.jpg
>> :width: 80%
>> :alt: Supercomputer archeticture
>> :align: bottom

>> and use the tag(s) in the table

>> =================== ================
>> |left-image| |right-image|

>> left caption right caption
>> =================== ================

(this is a simple table syntax, the | are not table lines but
mark substitutions).

Günter

Boris Kheyfets

unread,
Aug 28, 2012, 5:19:01 AM8/28/12
to sphin...@googlegroups.com
Doesn't work:

.. |left-image| image:: _static/SuperCompArch.jpg

      :width: 80%
      :alt: Supercomputer archeticture
      :align: bottom

.. |right-image| image:: _static/ClustArch.jpg
      :width: 80%

      :alt: Cluster archeticture
      :align: bottom

============  =============

|left-image|  |right-image|

left caption  right caption
============  =============

screenshot


Boris.

Guenter Milde

unread,
Aug 30, 2012, 7:41:14 AM8/30/12
to sphin...@googlegroups.com
On 2012-08-28, Boris Kheyfets wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> Doesn't work:

> .. |left-image| image:: _static/SuperCompArch.jpg
> :width: 80%
> :alt: Supercomputer archeticture
> :align: bottom

> .. |right-image| image:: _static/ClustArch.jpg
> :width: 80%
> :alt: Cluster archeticture
> :align: bottom

>============ =============
>|left-image| |right-image|

> left caption right caption
>============ =============

> screenshot <http://farm9.staticflickr.com/8434/7879097568_94e652749f_s.jpg>


If I interpret the screenshot right, the problem is that the left caption is
missing, right?

Could you have a look at the generated HTML file, whether it is already
missing there?

Did you get warnings or errors?

How about PDF export, does it work?


Günter


> On Monday, August 27, 2012 5:40:43 PM UTC+4, Guenter Milde wrote:

>> On 2012-08-27, Boris Kheyfets wrote:

>> > [-- Type: text/plain, Encoding: quoted-printable --]

...

No TOFU please.


Boris Kheyfets

unread,
Aug 31, 2012, 5:30:51 AM8/31/12
to sphin...@googlegroups.com
Oh I am sorry -- I've made a wrong link to screenshoot here's a right one:
screenshot.

I get no warning or errors, and here's html code (I hope googlegropus will leave it intact):

<table border="1" class="docutils">
<colgroup>
<col width="48%" />
<col width="52%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><img alt="Supercomputer archeticture" class="align-bottom" src="_images/SuperCompArch.jpg" style="width: 80%;" /></td>
<td><img alt="Cluster archeticture" class="align-bottom" src="_images/ClustArch.jpg" style="width: 80%;" /></td>
</tr>
<tr class="row-even"><td>left caption</td>
<td>right caption</td>
</tr>
</tbody>
</table>

So there's indeed a class="align-bottom" (though I don't see how I would center it also). But it doesn't work. Perphaps one should add the class to css... img.aligh-bottom? td.allign-bottom?

Guenter Milde

unread,
Sep 3, 2012, 8:49:10 AM9/3/12
to sphin...@googlegroups.com
On 2012-08-31, Boris Kheyfets wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> Oh I am sorry -- I've made a wrong link to screenshoot here's a right one:
> screenshot <http://farm9.staticflickr.com/8434/7879097568_94e652749f_b.jpg>.

> I get no warning or errors, and here's html code

...

> So there's indeed a class="align-bottom" (though I don't see how I would
> center it also). But it doesn't work. Perphaps one should add the class to
> css... img.aligh-bottom? td.allign-bottom?

Indeed, there is no CSS rule for align-bottom in Docutils' default style
sheet (html4css1.css). Furthermore, I don't see a way to define a rule
for image.align-bottom, as the valign (top/bottom) property should be
defined for the containing element. This means that the "image" directive
option

:align: top/bottom

does not make sense with HTML output currently. (The reST specs have the
caveat: "The specific behavior depends upon the browser or rendering
software used.")

The desired output can be achieved adding a valign arg to the relevant row
(e.g. via post-processing):

<table border="1" class="docutils">
<colgroup>
<col width="48%" />
<col width="52%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd" valign="bottom">
<td><img alt="Supercomputer archeticture" class="align-bottom" src="_images/SuperCompArch.jpg" style="width: 80%;" /></td>
<td><img alt="Cluster archeticture" class="align-bottom" src="_images/ClustArch.jpg" style="width: 80%;" /></td></tr><tr class="row-even"><td>left caption</td><td>right caption</td>
</tr>
</tbody>
</table>

A similar effect should be achievable with

<tr class="row-odd align-bottom">

and a CSS rule for ``tr.align-bottom``. However, reST does not offer a
way to pass class arguments to table columns, rows, or cells.

If all rows can be bottom (instead of top) aligned, you might give a class
to the whole table and define a rule for ``table.align-bottom tr``.
If all rows in all tables can ... you don't even need a class for the table.
You might need a more specific CSS selector to override the top alginment,
though.

Günter

Reply all
Reply to author
Forward
0 new messages