【问题标题】:org-mode: add a header to a table programmaticallyorg-mode:以编程方式将表头添加到表中
【发布时间】:2016-02-25 18:31:39
【问题描述】:

我有一个在 org-mode 中定义的表:

`#+RESULTS[4fc5d440d2954e8355d32d8004cab567f9918a64]: table
|  7.4159 | 3.0522 |  5.9452 |
| -1.0548 | 12.574 | -6.5001 |
|  7.4159 | 3.0522 |  5.9452 |
|  5.1884 | 4.9813 |  4.9813 |
`

我想生成下表:

#+caption: Caption of my table | | group 1 | group 2 | group 3 | |--------+---------+---------+---------| | plan 1 | 7.416 | 3.052 | 5.945 | | plan 2 | -1.055 | 12.574 | -6.5 | | plan 3 | 7.416 | 3.052 | 5.945 | | plan 4 | 5.1884 | 4.9813 | 4.9813 |

我怎样才能做到这一点?这是我尝试过的(在 R 中):

`
 #+begin_src R :colnames yes :var table=table :session  
data.frame(table)
 #+end_src
`

但当然它不起作用,这是我得到的:

`#RESULTS:
| X7.4159 | X3.0522 | X5.9452 |
|---------+---------+---------|
| -1.0548 |  12.574 | -6.5001 |
|  7.4159 |  3.0522 |  5.9452 |
|  5.1884 |  4.9813 |  4.9813 |`

有什么建议吗?

谢谢!

【问题讨论】:

    标签: r emacs org-mode org-table


    【解决方案1】:

    这非常接近。首先定义这个函数:

    #+BEGIN_SRC emacs-lisp
    (defun add-caption (caption)
      (concat (format "org\n#+caption: %s" caption)))
    #+END_SRC
    

    接下来,使用这种 src 块。我使用 python,但它也应该在 R 中工作,你只需要 :wrap。我通过var传入你的数据,如果你在块中生成数据,你不需要它。

    #+BEGIN_SRC python :results value :var data=data :wrap (add-caption "Some really long, uninteresting, caption about data that is in this table.")
    data.insert(0, ["", "group 1", "group 2", "group 3"])
    data.insert(1, None)
    return data
    #+END_SRC
    

    这个输出

    #+BEGIN_org
    #+caption: Some really long, uninteresting, caption about data that is in this    table.
    |        | group 1 | group 2 | group 3 |
    |--------+---------+---------+---------|
    | plan 1 |   7.416 |   3.052 |   5.945 |
    | plan 2 |  -1.055 |  12.574 |    -6.5 |
    | plan 3 |   7.416 |   3.052 |   5.945 |
    | plan 4 |  5.1884 |  4.9813 |  4.9813 |
    #+END_org
    

    我认为它也可以导出。

    【讨论】:

    • 谢谢,这正是我想要的!
    猜你喜欢
    • 2020-11-22
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 2011-02-18
    • 2012-10-23
    • 2023-03-15
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多