简单表格的单个单元格中有多行文本?

问题描述 投票:0回答:6

我发现了这个问题,但我不想在我的单元格中出现明确的

<br>
;我只是希望它在必要时换行。

例如,

================  ============
a short sentence  second cell
a much longer     bottom right
  sentence
================  ============

我想要“一个更长的句子”全部适合一个单元格。我需要使用very很长的文本行,除非我能找到一种方法来换行。这可能吗?

我正在使用 NoTex w/PDF 输出(如果相关)。

restructuredtext
6个回答
14
投票

有一个干净的方法。问题是默认情况下列设置为不换行,这就是您获得滚动的原因。要解决这个问题,您必须使用以下内容覆盖 css:

/* override table no-wrap */
.wy-table-responsive table td, .wy-table-responsive table th {
    white-space: normal;
}

6
投票

简单表格样式不支持换行块。使用网格样式,如下所示:

+------------------+--------------+
| a short sentence | second cell  |
+------------------+--------------+
| a much longer    | bottom right |
| sentence         |              |
+------------------+--------------+

这些表使用起来比较繁琐,但它们更灵活。有关详细信息,请参阅完整文档


5
投票

此问题的解决方法是使用替换指令:

================  ============
a short sentence  second cell
|long_sentence|   bottom right
================  ============

.. |long_sentence| replace:: a much longer sentence

2
投票

所提供的示例 ddbeck 可能有效,因为句子太短。如果句子的长度不适合屏幕,则该句子将不会换行。相反,表格将创建一个水平滚动条。没有干净的方法来解决这个问题。您可以隐式使用管道来隐式更改行,就像您在here看到的那样。

如果您想要以重组文本、更实用的方式编写表格的替代方案,您可以在 Sphinx/Rest Memo 中查看。


0
投票

我编写了一个Python实用程序来格式化具有多行单元格的固定宽度纯文本表格:https://github.com/kkew3/tabulate。希望有帮助。


0
投票

list-table语法可能适合这里:

.. list-table::

   * - a short sentence
     - second cell
   * - A "much" longer
       sentence.
       
       A table cell may also contain more than one paragraph.
       
     - bottom right       
© www.soinside.com 2019 - 2024. All rights reserved.