Suppose I have a table created by org-mode
| thing | value |
| t1 | 1 |
| t2 | 3 |
| t3 | 21 |
|-------+-------|
| total | 25 |
Is there a way inside org mode document to get the value from the total value cell in the table? (apart from manually copy the value)
To save the document, either press the save icon, or press C-x C-s, call it 1.org. Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores.
The easiest way to create a table is to directly type the "|" character at the beginning of a line, or after any amount of white space. This will put you in the first field of an atomic table. Once you've finished editing this cell, you can jump to the next one by pressing TAB .
Emacs has included Org Mode as a major mode by default since 2006. Bastien Guerry is the current maintainer, in cooperation with an active development community. Since its success in Emacs, some other systems now provide functions to work with org files.
To create a text-based table from scratch, type M-x table-insert . This command prompts for the number of table columns, the number of table rows, cell width and cell height.
The following post addresses your same question: http://permalink.gmane.org/gmane.emacs.orgmode/28056
You should name your table first, then refer to it via an inline src call:
#+TBLNAME: test-table
| thing | value |
|-------+-------|
| t1 | 1 |
| t2 | 3 |
| t3 | 21 |
|-------+-------|
| total | 25 |
The result I wanted is src_emacs-lisp[:var d=test-table[6,1]]{d}
Explanation: you call a very trivial elisp inline source block that only prints the variable d
, which was assigned to an element in the table.
If you want the second column of the last row, you can try:
The result I wanted is src_emacs-lisp[:var tbl=test-table]{(nth 1 (nth (- (length tbl) 1) tbl))}
Where the 1
gets the 2nd item, and the (- (length tbl) 1)
gets the last row (note that this last example is not purist LISP, just works).
Here we get the complete table into elisp (as a list of lists), and extract the desired item through list manipulation.
Note that the actual result will be substituted during export. You won't see it magically in the org-mode text itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With