使用 restructuredText 网格表设置列宽
Setting Column Width with restructuredText Grid Tables
我在 rST 中有以下网格 table。我想控制 HTML 输出 的列宽 以便 Field type
占据 table 宽度的 20%,Description
占30%,Example
占50%。
+-------------+-----------------+-----------------------+
|Field type |Description |Example |
+-------------+-----------------+-----------------------+
..tablularcolumns
指令没有影响,组合 ..table
和 :width:
也没有影响。例如下面的没有影响。
.. tabularcolumns:: |p{2cm}|p{3cm}|p{5cm}|
以下 SO link 处的答案无效。
How to fix column width in reStructuredText tables?
任何推荐都将彻底祝福
两个选项。
对表格使用 widths
option。
.. 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>
我在 rST 中有以下网格 table。我想控制 HTML 输出 的列宽 以便 Field type
占据 table 宽度的 20%,Description
占30%,Example
占50%。
+-------------+-----------------+-----------------------+
|Field type |Description |Example |
+-------------+-----------------+-----------------------+
..tablularcolumns
指令没有影响,组合 ..table
和 :width:
也没有影响。例如下面的没有影响。
.. tabularcolumns:: |p{2cm}|p{3cm}|p{5cm}|
以下 SO link 处的答案无效。
How to fix column width in reStructuredText tables?
任何推荐都将彻底祝福
两个选项。
对表格使用 widths
option。
.. 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>