How to center figure caption in Sphinx?

2,520 views
Skip to first unread message

陳韋任

unread,
Dec 13, 2012, 1:51:24 AM12/13/12
to sphin...@googlegroups.com
Hi all,
 

Currently I use following syntax to put my figure on the document,

  .. figure:: ../Fig/Fig2_4.png
  :align: center

  caption
 

The figure itself is centered, but the caption below it is left align. Anyone can give me a hint on how to center the caption?

Thanks!

Robert Lehmann

unread,
Dec 18, 2012, 7:04:39 AM12/18/12
to sphin...@googlegroups.com
You can put a class on the whole figure with :figclass: which you can then style in your CSS as you please.  The default theme has a "align-center" class which handily already has "text-align: center;" set for you.

陳韋任

unread,
Dec 27, 2012, 3:38:42 AM12/27/12
to sphin...@googlegroups.com
Hi Rober,

  Thanks for your reply, but I don't understand what I should do. Could you give me an example code
to illustrate a little bit more? Say, what should I change in the code below? 


  .. figure:: ../Fig/Fig2_4.png
  :align: center

  caption

 Thanks again. :-)

Robert Lehmann於 2012年12月18日星期二UTC+8下午8時04分39秒寫道:

Robert Lehmann

unread,
Dec 30, 2012, 2:46:59 AM12/30/12
to sphin...@googlegroups.com
Ugh, I checked back and ":align: center" and ":figclass: align-center" seem to have the same effect for HTML.  My guess would be that your theme omits a declaration such as the one found in basic.css:

.align-center {
    text-align: center;
}

If your theme has another class that features such an alignment clause (say, the CSS class is called foobar) then you can readily use it like this:

.. figure:: ../Fig/Fig2_4.png
   :figclass: foobar

For further advice on themes, please resort to sphinx-users (sphinx-dev is aimed at development of Sphinx.)

Cheers,
Robert
Reply all
Reply to author
Forward
0 new messages