Python sphinx 表根据原始内容自动调整列宽,而不考虑指令
假设您使用Sphinx2.x编写了一个文档,并在其中创建了一个表。将指令放在某些表格单元格中,如下所示:Python sphinx 表根据原始内容自动调整列宽,而不考虑指令,python-sphinx,substitution,restructuredtext,Python Sphinx,Substitution,Restructuredtext,假设您使用Sphinx2.x编写了一个文档,并在其中创建了一个表。将指令放在某些表格单元格中,如下所示: No directive (good) +---------+----------------------------------------------------------------------------------------------------------+ | Country | Cities
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源代码,您将看到每列的
宽度:##%
发生了什么
<colgroup>
<col style="width: 8%">
<col style="width: 92%">
</colgroup>
在Sphinx将rst文件转换为HTML、PDF等之前,是否有任何方法进行控制。?我同意我可以按照您的建议,通过定制CSS代码来更新HTML产品中的colgroup标记。我还可以使用sed命令来查找和替换HTML页面的这些部分。但如果产品是PDF,那就更麻烦了。小点:Sphinx使用docutils,它转换rst。你必须深入研究文档,这不是我认为的好时机。
<colgroup>
<col style="width: 36%">
<col style="width: 64%">
</colgroup>
table.docutils>colgroup {
display: none;
}