Org-mode表格:排除导出的列

6

我有一组在org-mode中的表格需要导出,但是我希望某些列用于计算和代码块使用时被排除在LaTeX导出之外。

我记得有一种方法可以通过在表格下方指定要导出的列范围来实现,但我在网上找不到任何相关参考,所以很可能是我做梦了。

5个回答

6

另一种实现方法是在org文件的LaTeX头选项中定义一个“隐藏”列类型H,然后使用#+ATTR_LATEX: :align llH来指示在导出时隐藏第三列(来源):

#+LATEX_HEADER: \usepackage{array}
#+LATEX_HEADER: \newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

#+ATTR_LATEX: :align llH
|-----+-------+------|
|   2 | 1/2   | junk |
|   4 | 1/4   | junk |
|   8 | 1/2   | junk |

3

目前看来这似乎是唯一的方法,尽管它不像链接所示那样在导出时起作用。干杯。 - Germano

1
我使用了Michael Brand在这里提出的解决方案,并由Derek Feichtinger这里进行了归类(请确保以原始模式查看文件,否则GitHub会隐藏源代码)。
为方便起见,我在下面重现了代码:
* Exporting tables with some columns hidden

  It is desirable to be able and hide columns in exported output. This is often the
  case in tables where a lot of computations are done, and where intermediate
  results end up in columns that one does not want to end up in the exported document.

  This functionality is currently not available by standard org, but since this is Emacs, a simple function
  implementing this functionality was published by [[https://github.com/brandm][Michael Brand]] within this [[http://lists.gnu.org/archive/html/emacs-orgmode/2016-05/msg00027.html][emacs-orgmode thread]].

  #+BEGIN_SRC emacs-lisp :results silent :exports source
    (defun dfeich/org-export-delete-commented-cols (back-end)
      "Delete columns $2 to $> marked as `<#>' on a row with `/' in $1.
    If you want a non-empty column $1 to be deleted make it $2 by
    inserting an empty column before and adding `/' in $1."
      (while (re-search-forward "^[ \t]*| +/ +|\\(.*|\\)? +\\(<#>\\) *|" nil t)
    (goto-char (match-beginning 2))
    (org-table-delete-column)
    (beginning-of-line)))
    (add-hook 'org-export-before-processing-hook #'dfeich/org-export-delete-commented-cols)
    ;; (remove-hook 'org-export-before-processing-hook #'dfeich/org-export-delete-commented-cols)
  #+END_SRC  

  The exported table will have col2 removed.

  |   | col1 | col2 | col3 |
  | / |  <r> | <#>  |      |
  |   |   a1 | a2   | a3   |
  |   |   b1 | b2   | b3   |

0

这个功能允许你删除一行,但是我需要删除一些列。还是谢谢。 - Germano
很难!我还没有掌握Org-mode电子表格。 - Mauvis Ledford

0
我发现最方便的方法是:
  1. 使用:noexport:标签使表格不可导出,
  2. 使用elisp选择我想要导出的列,并使结果可导出。
以下是一个使用elisp的示例。
* Hidden :noexport:
#+NAME: google
| file      | total | other | p  |
|-----------+-------+-------+----|
| de-01.pdf |   312 |    76 | 76 |
| de-02.pdf |   428 |   101 | 77 |
| de-03.pdf |  1069 |   217 | 80 |

* Exported
Here it comes.

#+begin_src elisp :var data=google :colnames yes
;; select 0th and 3rd column from a table accessible with 'google' name
;; and do some math on it
  (mapcar (lambda (e) (list (nth 0 e) (nth 3 e))) data)
#+end_src

#+RESULTS:
| file      | p  |
|-----------+----|
| de-01.pdf | 76 |
| de-02.pdf | 77 |
| de-03.pdf | 80 |

您还可以使用源代码块支持的任何其他语言来循环遍历结果并生成所需的输出。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接