简体   繁体   中英

getting a value outside a table in emacs org-mode

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM