使用重构的文本网格表设置列宽



我在 rST 中有以下网格表。我想控制 HTML 输出的列宽,以便Field type占据表格宽度的 20%,Description占用 30%,Example占据 50%。

+-------------+-----------------+-----------------------+
|Field type   |Description      |Example                |
+-------------+-----------------+-----------------------+

..tablularcolumns指令没有影响,..table:width:的组合也没有影响。例如,以下内容没有影响。

.. tabularcolumns:: |p{2cm}|p{3cm}|p{5cm}|

以下SO链接中的答案不起作用。

如何修复重组文本表中的列宽?

任何建议都将得到彻底的祝福。

两个选项。

对表使用widths选项。

.. table:: This is my table
    :widths: 20 30 50
    +-------------+-----------------+-----------------------+
    |Field type   |Description      |Example                |
    +-------------+-----------------+-----------------------+

修改主题的 CSS 并使用 :nth-child CSS 伪选择器。

td:nth-child(1) {
    width: 20%;
}
td:nth-child(2) {
    width: 30%;
}
td:nth-child(3) {
    width: 50%;
}

第一个选项的输出如下:

<table border="1" class="colwidths-given docutils" id="id1">
<caption><span class="caption-text">This is my table</span><a class="headerlink" href="#id1" title="Permalink to this table">¶</a></caption>
<colgroup>
<col width="20%">
<col width="30%">
<col width="50%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Field type</td>
<td>Description</td>
<td>Example</td>
</tr>
</tbody>
</table>

最新更新