4

Say I have a table in reStructuredText like:

+---------------+---------------------------+
| key           | value                     |
+===============+===========================+
| short_word    | value_1                   |
+---------------+---------------------------+
| really_long_  | value 2                   |
| word_I_want_  |                           |
| to_break      |                           |
+---------------+---------------------------+

Is there any way to break the word in the bottom left cell, i.e. with a line continuation escape character or anything like that so that it still appears as a single word in the output?

In particular I'm using Sphinx to document my Python documentation and because of the trailing underscore character it's interpreting the first line as a link target which generates an error.

snth
  • 5,194
  • 4
  • 39
  • 48

3 Answers3

6

Ok, after some experimentation it looks like the usual backslash \ line continuation character works, i.e.

+---------------+---------------------------+
| key           | value                     |
+===============+===========================+
| short_word    | value_1                   |
+---------------+---------------------------+
| really_long\  | value 2                   |
| _word_I_want\ |                           |
| _to_break     |                           |
+---------------+---------------------------+

I found that I still had to move the underscore character to the next line otherwise the first line was still interpreted as a link target although the word in the resulting HTML table was written as a continuous word.

snth
  • 5,194
  • 4
  • 39
  • 48
  • 1
    This did not work for me, the result still ends up on the same line. – Zitrax Apr 05 '13 at 12:26
  • @Zitrax I probably explained myself badly. What I wanted was for it to appear as one word on one line in the final html document but I wanted to be able to write it over multiple lines. Therefore if you are finding that it ends up on the same line then that is the behaviour I was going for. – snth Apr 08 '13 at 09:17
2

Check out this suggestion to use reST substitutions to refer to long things by shorter things.

+---------------+---------------------------+
| key           | value                     |
+===============+===========================+
| short_word    | value_1                   |
+---------------+---------------------------+
| |long_word|   | value 2                   |
+---------------+---------------------------+

.. |long_word| replace:: really_long_word_I_want_to_break

I was having a similar problem with :ref:`Long Title <even-longer-name>` in tables, which you really can't easily break across lines. Substitutions solved it.

Community
  • 1
  • 1
medmunds
  • 5,950
  • 3
  • 28
  • 51
0

Add a bar and a space in front of your line:

+------------------+---------------------------+
| key              | value                     |
+==================+===========================+
| short_word       | value_1                   |
+------------------+---------------------------+
| | really_long    | value 2                   |
| | _word_I_want   |                           |
| | _to_break      |                           |
+------------------+---------------------------+
DrTox
  • 74
  • 1
  • 3