Orgmode: intestazione verticale

Sep 12 2020

è possibile creare anche un'intestazione verticale con la modalità org?

Qualcosa di simile (campi di colore ciano):

Puoi creare un'intestazione orizzontale come questa:

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

ma voglio anche un'intestazione verticale:

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

Il motivo è che voglio esportarlo in HTML.

L'HTML sarà simile a questo:

<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>

se supporta l'intestazione verticale dovrebbe essere qualcosa del genere:

<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>

Notare l' thelemento sul secondo blocco di codice invece di un tdelemento sul tbody. So di poterlo fare con JavaScript ma voglio sapere se org-modepotrebbe già supportarlo, il che renderebbe le cose molto più semplici.

Risposte

NickD Sep 12 2020 at 04:46

Per rendere la prima colonna una colonna di "intestazione", tutto ciò che devi fare è

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

globalmente o come variabile di file locale :

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

Per quanto ne so, non è possibile specificarlo per tabella.

Per esempio:

* 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:

verrà esportato in HTML esattamente come viene mostrato (ad eccezione dei colori).

Vedere la sezione Tabelle nell'esportazione HTML del manuale per altre variabili, ma attenzione alla #+ATTR_HTMLsintassi: è come mostrato sopra per le versioni recenti della modalità Org, ma il manuale mostra la vecchia sintassi:

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

che potresti ancora dover utilizzare, a seconda della versione. Aprirò un bug sul documento.


[VECCHIA RISPOSTA: quanto segue non risponde alla domanda ma potrebbe essere sufficientemente interessante lasciarlo qui.]

Se intendi qualcosa del genere:



* 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

la risposta è un SÌ enfatico.

Ho creato la tabella con la seguente serie di istruzioni:

  • M-x org-create-table RET 1x13 RET: che crea una tabella a colonna singola con 13 righe.
  • Digita .nella prima riga, 1nella seconda riga e poi continua a digitare S-<Enter>per riempire il resto delle righe.
  • M-x org-table-transpose-table-at-point RET per trasformarlo in una tabella a riga singola.
  • Premere TABper creare la seconda riga e passare alla prima colonna di essa.
  • Digita 1la prima colonna della seconda riga e continua a digitare S-<Enter>per completare il resto di quella colonna.

Ora hai la prima colonna e la prima riga, popolate con ciò che mostri nella tua tabella. Ora aggiungi una formula di tabella sotto la tabella come mostrato sopra e premi C-c C-c: il resto della tabella viene compilato (devi attivare Calc in anticipo: digita M-x calc RET qper farlo).

La formula della tabella dice: compila ogni altra cella della tabella (righe da 2 a ultime e colonne da 2 a ultime) con il prodotto dei numeri che trovi in ​​(riga 1, colonna corrente) e (riga corrente, colonna 1).