首页 > 解决方案 > 跨越多行的单元格中的文本换行 - Sphinx ReStructuredText

问题描述

当创建一个单元格跨越多行的表格时,我注意到文本的内容不会换行,而是增加了表格的宽度以产生水平滚动条。

例如考虑以下 RST,

+-------+-----------------+
|       |                 |
+-------+-----------------+
|       | This text must  |
+-------+ wrap over to    |
|       | the next line   |
+-------+-----------------+

建成后生产,

sphynx 构建输出

当我增加文本的长度时,表格会水平增长。我应该怎么做才能包装?现在,我通过手动插入带有“|”的换行符来强制它换行 但产生的输出看起来很糟糕。

标签: restructuredtext

解决方案


您将无法覆盖colgroupSphinx 中的标签。您可以尝试改用rst2html5 包,它不会生成colgroup. 另一种选择是使用 CSS 来控制列宽:

col:nth-child(1) {
  width: 200px;
}

col:nth-child(2) {
  width: 300px;
}
<table border="1" class="docutils">
<colgroup>
<col width="29%" />
<col width="71%" />
</colgroup>
<tbody valign="top">
<tr><td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr><td>&nbsp;</td>
<td rowspan="2">This text must
wrap over to
the next line</td>
</tr>
<tr><td>&nbsp;</td>
</tr>
</tbody>
</table>


推荐阅读