【问题标题】:Align leged text in figure caption Sphinx在图标题 Sphinx 中对齐有脚文本
【发布时间】:2017-07-06 16:43:19
【问题描述】:

我无法选择在 sphinx 中对齐图形的图例文本。

.. figure:: check_validity.png
   :align: center

   ..

   Left: the source layer

   Right: in blue the valid layer, in green the invalid layer and in red the error
   layer

这是结果:

但我想让两个标题都左对齐。不使用表格可以吗?

【问题讨论】:

  • 您想将图像相对于页面居中对齐吗?对于文本,您要相对于页面还是图像左对齐?
  • 我想将文本相对于图像左对齐。你知道这是否可能吗?

标签: python-sphinx restructuredtext


【解决方案1】:

是的,但它非常笨拙,需要自定义 CSS 来考虑每个图像的宽度。

这是 Sphinx 为我生成的 HTML:

<div class="figure align-center">
    <img src="check_validity.png" />
    <div class="legend">
        <p>Some text</p>
        <p>Another sentence</p>
    </div>
</div>

根据您的主题,您需要:

  1. 获取图像的宽度 (WI)
  2. 获取内容区域 (WCA) 的宽度,如果它是一个流动的可变宽度区域,这可能是不可能的
  3. 计算左边距:LM = (WCA - WI)/2
  4. 使用 CSS 选择器将 LM 作为段落块的左边距

只使用表格要容易得多。欢迎来到 1990 年代!

这是reST标记:

.. rst-class:: table-center

+--------------------------------+
| .. figure:: check_validity.png |
|                                |
|   ..                           |
|                                |
|   Left: the source layer       |
|                                |
|   Right: in blue the valid     |
|   layer, in green the invalid  |
|   layer and in red the error   |
|   layer                        |
+--------------------------------+

您需要在 CSS 文件中添加自定义样式:

table.table-center {
    margin-left: auto;
    margin-right: auto;
}

【讨论】:

  • 好的,我发现没有简单的方法可以做到这一点。我不得不求助于 css 自定义样式表。谢谢!
猜你喜欢
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多