8

I have a table like this:

| Verse No | Verse      |
|          | <10>       |
|        1 | line1 li=> |
|        2 | line2 li=> |

I would like to view it as

| Verse No | Verse      |
|          | <10>       |
|        1 | line1 line |
|          | 1 line1    |
|        2 | line2 line |
|          | 2 line2    |

I am aware of C-c ` but that's not enough, I want to see all text simultaneously. Read only is OK if need be.

  • See if my answer here helps. – Joe Jan 17 at 21:43
13

org-mode has 2 table formats, the default org-table and the other is table.el.

Cell wrapping is available for tables in table.el format.

Try this

  1. Remove the extra row with <10> so your table will look similar to the example below:

    | Verse No | Verse             |
    |        1 | Line1 Line1 Line1 |
    |        2 | Line2 Line2 Line2 |
    

    Tip: Add a blank line above and below the table. The blank lines should prevent a bug when converting the table with C-c ~. Thanks to @ComproPrasad for troubleshooting and providing the workaround.

  2. Place your cursor, a.k.a the point, inside updated table then type C-c ~ and answer y. The updated table should look similar to example below:

    +----------+-------------------+
    | Verse No | Verse             |
    +----------+-------------------+
    |        1 | Line1 Line1 Line1 |
    +----------+-------------------+
    |        2 | Line2 Line2 Line2 |
    +----------+-------------------+
    
  3. Place your cursor inside updated table then type C-c ' and a new window or frame will appear.

  4. Type M-x t-r-t and each table cell should be highlighted.

  5. Place your cursor inside second column and type C-c C-c < until the column is the desired width.

    Tip: Use the universal argument key binding C-u to quickly repeat this step. For example, If your cell is 500 characters and you want to adjust the width to 10 characters do C-u 490 C-c C-c < which will repeat C-c C-c < command 490 times.

  6. Type C-c ' to finish editing table. These steps should leave you with a similar to the example below:

    +----------+------+
    | Verse No | Verse|
    +----------+------+
    |        1 |Line1 |
    |          |Line1 |
    |          |Line1 |
    +----------+------+
    |        2 |Line2 |
    |          |Line2 |
    |          |Line2 |
    +----------+------+
    

Thanks for asking your question!
Hope that helped!


This answer tested using:
emacs version: GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
org version: Org mode version 9.1.2

  • 1
    Step 4 is not needed (at least in current emacs v. 26). Pressing C-c ~ as the step 7 converts the table.el table back to editable org table. – Heikki Jan 17 '18 at 7:44
  • @Heikki Great to know! Thanks! On v.25 I needed to add step 4 because to table wasn’t being recognized but wasn’t throwing any errors either. Did you want me to add step 7 C-c ~ to convert back to org-table format? – Melioratus Jan 17 '18 at 18:21
  • 1
    is there an option to speed up step 5, say when I have 500 char of content and I want them wrapped to 10 chars? – user2740 Jan 19 '18 at 12:27
  • 1
    Made a video: youtu.be/Jo4RlPqs0_c – Compro Prasad Aug 6 '18 at 20:27
  • 1
    what is step 4? Is t-r-t shorthand for another command? I've found that when dealing with tables that have text with embedded links, after step 3, only the column headings are selected, and I need a way to select each table cell, as in step 4. However, I don't know what step 4 is actually referring to, since M-x t-r-t shows nothing for me with org-mode 9.1.9 – adamc Nov 14 '18 at 0:50
4

Adjust Column Width with Wrap Around

Here is a solution adapted for org-mode 9.1.13, Spacemacs (0.200.13), emacs 26.1 for convenience.

Starting with the following content at a buffer in org-mode:

| Verse No | Verse             |
|        1 | Line1 Line1 Line1 |
|        2 | Line2 Line2 Line2 |

must leave a NEWLINE on top of the above table to avoid the bug of table.el.

  1. Convert the table to table.el format by C-c ~ +----------+-------------------+ | Verse No | Verse | +----------+-------------------+ | 1 | Line1 Line1 Line1 | +----------+-------------------+ | 2 | Line2 Line2 Line2 | +----------+-------------------+
  2. Directly adjust the column width by SPC u 10 SPC SPC table-narrow-cell +----------+---------+ | Verse No | Verse | +----------+---------+ | 1 | Line1 | | |Line1 | | |Line1 | +----------+---------+ | 2 | Line2 | | |Line2 | | |Line2 | +----------+---------+

It works for my configuration without entering into table.el mode. With my spacemacs, C-u 10 C-c C-c < does not work.

  • My newer spacemacs setup no longer works with the above solution. But I found that conventing to table.el format, then I can manually adjust the line wrap. After manual editing, then I can convert it back, and get the desired wraps. – Yu Shen Jul 23 at 18:14
3

Once you follow along the accepted answer and fixed the size of a long column in an existing table, toggling table-fixed-width-mode by M-x table-fixed-width-mode seems to do the trick of automatically wrapping (future) long lines of text in a column in table edit mode. You enter table edit mode by keying C-c '

Tested on: Emacs 25.2.2, Org-Mode 9.1.6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.