对齐图形标题 Sphinx 中的有腿文本
Align leged text in figure caption Sphinx
我无法选择对齐 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
这是结果:
但我希望两个标题都左对齐。这可以不使用表格吗?
是的,但它非常笨拙,需要自定义 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>
根据您的主题,您需要:
- 获取图像的宽度(WI)
- 获取内容区域 (WCA) 的宽度,如果它是一个流动的可变宽度区域,这可能是不可能的
- 计算左边距:LM = (WCA - WI)/2
- 使用 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;
}
我无法选择对齐 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
这是结果:
但我希望两个标题都左对齐。这可以不使用表格吗?
是的,但它非常笨拙,需要自定义 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>
根据您的主题,您需要:
- 获取图像的宽度(WI)
- 获取内容区域 (WCA) 的宽度,如果它是一个流动的可变宽度区域,这可能是不可能的
- 计算左边距:LM = (WCA - WI)/2
- 使用 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;
}