'Multiple lines of text in single cell of simple table?

I found this question, but I don't want explicit <br>s in my cell; I just want it to line-wrap where necessary.

e.g.,

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

I want "a much longer sentence" to all fit in one cell. I'd need to use very long lines of text unless I can find a way to wrap it. Is this possible?

I'm using NoTex w/ PDF output if relevant.



Solution 1:[1]

The simple table style does not support wrapping blocks. Use the grid style instead, like this:

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

These tables are more tedious to work with, but they're more flexible. See the full documentation for details.

Solution 2:[2]

There is a clean way. The issue is by default the columns are set to no-wrap, so that's why you get the scroll. To fix that you have to override the css with the following:

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

Solution 3:[3]

A workaround for this problem is to use a replace directive:

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

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

Solution 4:[4]

The example ddbeck presented may work because the sentence is to short. In the case of the lenght of the sentence dont fit in the screen, the sentence will not continue in a new line. Instead, the table will create a horizontal scrollbar. There is no clean way for solving this problem. You can implicit use pipe to implicitly change line like you saw here.

If you want alternatives to write your tables in restructuredtext, more pratical ways, you can check it in Sphinx/Rest Memo.

Solution 5:[5]

I wrote a python utility to format fixed-width plaintext table with multiline cells: https://github.com/kkew3/tabulate. Hope it helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ddbeck
Solution 2 Matt Cannon
Solution 3 Olivier
Solution 4 Community
Solution 5