12

Here is my question, I have multiple lines of text, line this:

line1
line2
line3
...

And I want to create a org-mode table like this:

| C1    |
|-------|
| line1 |
| line2 |
| line3 | 
| ....  |

Is it possible ?

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
lllllllllllll
  • 579
  • 1
  • 4
  • 14

2 Answers2

16

Yes, that's possible:

  1. Select lines you want to add to the table.

  2. Press C-c | (org-table-create-or-convert-from-region). This will give you:

    | line1 |
    | line2 |
    | line3 |
    

Now all you need to do is add the header line. Here's one way of doing that:

  1. With point (the cursor) on line1, press C-o (org-open-line), then enter C1.

  2. Press C-c - (org-ctrl-c-minus) to insert the separator.

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
11

Let's say you have an empty table as shown below and you want to paste few lines in column C1.

|----+----|
| C0 | C1 |
|----+----|
|    |    |
|----+----|

Step 1: Copy the lines as a rectangle

Copy the lines using copy-rectangle-as-kill (C-x r M-w) or cut them using kill-rectangle (C-x r k). Below shows the point and mark locations I used when copying/cutting the rectangle.

▯ine1
line2
line3▮

Step 2: Make space for the lines to be inserted in the table

|----+----|
| C0 | C1 |
|----+----|
|    |▮   |
|----+----|

With the cursor in the desired column as shown above, call org-open-line for the required number of times. For this example, we'll call it twice.

|----+----|
| C0 | C1 |
|----+----|
|    |▮   |
|    |    |
|    |    |
|----+----|

Step 3: Paste the rectangle

Paste the rectangle using M-x yank-rectangle or C-x r y. That will give you:

|----+----|
| C0 | C1 |
|----+----|
|    |line1    |
|    |line2    |
|    |line3    |
|----+----|

Hit C-c C-c to auto align the table.

|----+-------|
| C0 | C1    |
|----+-------|
|    | line1 |
|    | line2 |
|    | line3 |
|----+-------|
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179