11

I'm wondering whether it's possible to display the result of calculations performed on table data, outside of a table.

For example, suppose I have a table of with a list of names. Is it possible to have plain text that says something like "This below list contains [ ] names." and have [ ] contain the result of counting the table?

9

You can use an inline babel code block and the lisp function org-table-get-remote-range for getting access to table ranges like in the following example (the number 3 after the source block is what it produced when C-c C-c is executed on it)

  #+TBLNAME: table1
  | Name    | Points |
  |---------+--------|
  | Andreas |      5 |
  | Barbara |      8 |
  | Carl    |      7 |
  |---------+--------|
  | Total   |     20 |
  #+TBLFM: @5$2=vsum(@I..@II)

  Now I insert in the text the number of names in the above table: 
  src_emacs-lisp[:results raw]{(length (org-table-get-remote-range "table1" "@I$1..@II$1" ))} 3
  • In my Emacs settings, [:results raw] does not show the results, [:results value raw] succeeded. However every time I C-c C-c, or C-c C-v C-b, redundant same result is repeated. I don't know why and I don't have a solution for the redundant results. – RUserPassingBy Jun 26 '15 at 3:52
  • 1
    value should be the default setting, but your making it explicit is certainly more correct. In regard to the repetition of the insertion of the results with every subsequent execution of C-c C-c, this is an inherent problem, since the result is not wrapped in any kind of markers which would enable Org to determine the limits. One would have to cook up some solution using in-text markers that are invisible on export. The current situation is not optimal, I agree. – dfeich Jun 27 '15 at 7:40
  • Thank you for your precise explanation, I understand. I will keep in mind the inherent problem. Your solution in-line block is great! – RUserPassingBy Jun 27 '15 at 8:12

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.