我有一组在org-mode中的表格需要导出,但是我希望某些列用于计算和代码块使用时被排除在LaTeX导出之外。
我记得有一种方法可以通过在表格下方指定要导出的列范围来实现,但我在网上找不到任何相关参考,所以很可能是我做梦了。
另一种实现方法是在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 |
#+ORGTBL: SEND some-name orgtbl-to-latex :skipcols (3)
|-----+-------+------|
| 2 | 1/2 | junk |
| 4 | 1/4 | junk |
| 8 | 1/2 | junk |
C-c C-e
导出可能不可行,因为自2010年11月起在http://comments.gmane.org/gmane.emacs.orgmode/33946中提供了相同的答案。* 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 |
http://www.gnu.org/software/emacs/manual/html_mono/org.html#The-spreadsheet
3.5.6 编辑和调试公式
使用'/'
表示:不要导出此行。对于包含缩小的''标记或列组标记的行非常有用。
请注意,为了实现此功能,您必须使用第一列来提供额外的信息。
* 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 |
您还可以使用源代码块支持的任何其他语言来循环遍历结果并生成所需的输出。