1

is it possible to create a vertical header with org mode, too?

Something like this (cyan colored fields):

enter image description here

You can create a horizontal header like this:

| Header  | Header  | Header  | Header  | Header  |
|---------+---------+---------+---------+---------|
| Content | Content | Content | Content | Content |

but I want also a vertical header, too:

| Header | Header  | Header  | Header  | Header  |
|--------+---------+---------+---------+---------|
| Header | Content | Content | Content | Content |
| Header | Content | Content | Content | Content |

The reason for this is I want to export it to HTML.

The HTML will look like this:

<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
        <colgroup>
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
        </colgroup>
        <thead>
            <tr>
                <th class="org-right" scope="col">.</th>
                <th class="org-right" scope="col">1</th>
                <th class="org-right" scope="col">2</th>
                <th class="org-right" scope="col">3</th>
                <th class="org-right" scope="col">4</th>
                <th class="org-right" scope="col">5</th>
                <th class="org-right" scope="col">6</th>
                <th class="org-right" scope="col">7</th>
                <th class="org-right" scope="col">8</th>
                <th class="org-right" scope="col">9</th>
                <th class="org-right" scope="col">10</th>
                <th class="org-right" scope="col">11</th>
                <th class="org-right" scope="col">12</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="org-right">1</td>
                <td class="org-right">1</td>
                <td class="org-right">2</td>
                <td class="org-right">3</td>
                <td class="org-right">4</td>
                <td class="org-right">5</td>
                <td class="org-right">6</td>
                <td class="org-right">7</td>
                <td class="org-right">8</td>
                <td class="org-right">9</td>
                <td class="org-right">10</td>
                <td class="org-right">11</td>
                <td class="org-right">12</td>
            </tr>
        </tbody>
    </table>

if it supports vertical header it should be something like this:

<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
        <colgroup>
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
            <col class="org-right">
        </colgroup>
        <thead>
            <tr>
                <th class="org-right" scope="col">.</th>
                <th class="org-right" scope="col">1</th>
                <th class="org-right" scope="col">2</th>
                <th class="org-right" scope="col">3</th>
                <th class="org-right" scope="col">4</th>
                <th class="org-right" scope="col">5</th>
                <th class="org-right" scope="col">6</th>
                <th class="org-right" scope="col">7</th>
                <th class="org-right" scope="col">8</th>
                <th class="org-right" scope="col">9</th>
                <th class="org-right" scope="col">10</th>
                <th class="org-right" scope="col">11</th>
                <th class="org-right" scope="col">12</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th class="org-right">1</th>
                <td class="org-right">1</td>
                <td class="org-right">2</td>
                <td class="org-right">3</td>
                <td class="org-right">4</td>
                <td class="org-right">5</td>
                <td class="org-right">6</td>
                <td class="org-right">7</td>
                <td class="org-right">8</td>
                <td class="org-right">9</td>
                <td class="org-right">10</td>
                <td class="org-right">11</td>
                <td class="org-right">12</td>
            </tr>
        </tbody>
    </table>

Note the th element on the second code block instead of an td element on the tbody. I know I can do this with JavaScript but I want to know if org-mode may already support it, which would make things a lot easier.

1
  • Updated question for better understanding. – PortStone Sep 12 '20 at 19:01
0

To make the first column a "header" column, all you have to do is

(setq org-html-table-use-header-tags-for-first-column t)

either globally, or as a local file variable:

# Local Variables:
# org-html-table-use-header-tags-for-first-column: t
# End:

AFAIK, you cannot specify it per table though.

For example:

* Multiplication table

  #+ATTR_HTML: :border 3 :rules all :frame border
  |  . |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |   9 |  10 |
  |----+----+----+----+----+----+----+----+----+-----+-----|
  |  1 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |   9 |  10 |
  |  2 |  2 |  4 |  6 |  8 | 10 | 12 | 14 | 16 |  18 |  20 |
  |  3 |  3 |  6 |  9 | 12 | 15 | 18 | 21 | 24 |  27 |  30 |
  |  4 |  4 |  8 | 12 | 16 | 20 | 24 | 28 | 32 |  36 |  40 |
  |  5 |  5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 |  45 |  50 |
  |  6 |  6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 |  54 |  60 |
  |  7 |  7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 |  63 |  70 |
  |  8 |  8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 |  72 |  80 |
  |  9 |  9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 |  81 |  90 |
  | 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |  90 | 100 |
  #+TBLFM: @2$2..@>$> = @1$0 * @0$1


* Local variables                                      :noexport:
# Local Variables:
# org-html-table-use-header-tags-for-first-column: t
# End:

will be exported to HTML exactly as you show (except for the colors).

See the Tables in HTML export section of the manual for other variables, but beware of the #+ATTR_HTML syntax: it's as I show above for recent versions of Org mode, but the manual shows the old syntax:

 #+ATTR_HTML: border="2" rules="all" frame="border"

which you might still have to employ, depending on your version. I'll open a bug about the doc.


[OLD ANSWER: the following does not answer the question but it might be sufficiently interesting to leave in here.]

If you mean something like this:



* Multiplication table


  |  . |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |   9 |  10 |  11 |  12 |
  |  1 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |   9 |  10 |  11 |  12 |
  |  2 |  2 |  4 |  6 |  8 | 10 | 12 | 14 | 16 |  18 |  20 |  22 |  24 |
  |  3 |  3 |  6 |  9 | 12 | 15 | 18 | 21 | 24 |  27 |  30 |  33 |  36 |
  |  4 |  4 |  8 | 12 | 16 | 20 | 24 | 28 | 32 |  36 |  40 |  44 |  48 |
  |  5 |  5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 |  45 |  50 |  55 |  60 |
  |  6 |  6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 |  54 |  60 |  66 |  72 |
  |  7 |  7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 |  63 |  70 |  77 |  84 |
  |  8 |  8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 |  72 |  80 |  88 |  96 |
  |  9 |  9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 |  81 |  90 |  99 | 108 |
  | 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |  90 | 100 | 110 | 120 |
  | 11 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 |  99 | 110 | 121 | 132 |
  | 12 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 | 108 | 120 | 132 | 144 |
  #+TBLFM: @2$2..@>$> = @1$0 * @0$1

the answer is an emphatic YES.

I created the table with the following set of instructions:

  • M-x org-create-table RET 1x13 RET: that creates a single column table with 13 rows.
  • Type . in the first row, 1 in the second row and then keep typing S-<Enter> to fill the rest of the rows.
  • M-x org-table-transpose-table-at-point RET to make it into a single row table.
  • Press TAB to create the second row and move to the first column of it.
  • Type 1 in the first column of the second row and then keep typing S-<Enter> to fill out the rest of that column.

You now have the first column and the first row, populated with what you show in your table. Now add a table formula under the table as shown above and press C-c C-c: the rest of the table gets filled out (you must activate Calc beforehand: type M-x calc RET q to do that).

The table formula says: fill out every other cell in the table (rows 2 to last and columns 2 to last) with the product of the numbers that you find in (row 1, current column) and (current row, column 1).

1
  • I didn't meant the calculation (but didn't knew that either, so thanks). I don't know how I can do a vertical header. I updated my question for better understanding. – PortStone Sep 12 '20 at 18:56

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.