假设您使用 Sphinx 2.x 编写一个文档并在其中创建一个表。将指令放入某些表格单元格中,如下所示:
No directive (good)
+---------+----------------------------------------------------------------------------------------------------------+
| Country | Cities |
+=========+==========================================================================================================+
| UK | London, Leeds, Glasgow, Sheffield, Bradford, Manchester, Edinburgh, Liverpool, Bristol, Cardiff, Belfast |
+---------+----------------------------------------------------------------------------------------------------------+
| US | New York, Los Angeles, Chicago, Houston, Phoenix, Philadelphia, San Antonio, San Diego, Dallas, San Jose |
+---------+----------------------------------------------------------------------------------------------------------+
With the directive (bad)
.. |the_united_kingdom_of_great_britain_and_northern_ireland| replace:: UK
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+
| Country | Cities |
+============================================================+==========================================================================================================+
| |the_united_kingdom_of_great_britain_and_northern_ireland| | London, Leeds, Glasgow, Sheffield, Bradford, Manchester, Edinburgh, Liverpool, Bristol, Cardiff, Belfast |
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+
| US | New York, Los Angeles, Chicago, Houston, Phoenix, Philadelphia, San Antonio, San Diego, Dallas, San Jose |
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+
比较这两个表:唯一的区别是第二个表中使用了 “UK” 的替代(替换)指令。
我相信这两个表看起来一定是相同的。但事实并非如此。
HTML
rst2pdf
我希望表自动调整操作按以下顺序进行:
但是 HTML 和 rst2pdf 似乎都在执行
这是设计好的吗?有没有办法(重新)优化第二个表的列宽?
查看 HTML 源代码,您将看到每列的
width: ##%
发生了什么。
<colgroup>
<col style="width: 8%">
<col style="width: 92%">
</colgroup>
和
<colgroup>
<col style="width: 36%">
<col style="width: 64%">
</colgroup>
尝试自定义样式:
table.docutils>colgroup {
display: none;
}
从0.18版本开始,Docutils的HTML5编写器默认为自动宽度表格列,因此大多数情况下这个问题都得到了解决。
要明确设置列宽,请使用以下任意一个 表...指令与 “宽度”选项:
.. |the_united_kingdom_of_great_britain_and_northern_ireland| replace:: UK
.. table::
:widths: 2, 5
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+
| Country | Cities |
+============================================================+==========================================================================================================+
| |the_united_kingdom_of_great_britain_and_northern_ireland| | London, Leeds, Glasgow, Sheffield, Bradford, Manchester, Edinburgh, Liverpool, Bristol, Cardiff, Belfast |
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+
| US | New York, Los Angeles, Chicago, Houston, Phoenix, Philadelphia, San Antonio, San Diego, Dallas, San Jose |
+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+