From e0f0e26a43868b883efd641f061897e08c822710 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 29 Jun 2010 10:10:52 -0700 Subject: [PATCH] library-of-babel: adding a booktabs latex exporting function --- contrib/babel/library-of-babel.org | 46 +++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org index 2e34e1d78..49172e0af 100644 --- a/contrib/babel/library-of-babel.org +++ b/contrib/babel/library-of-babel.org @@ -98,6 +98,50 @@ plot(data) * Tables ** LaTeX Table export +*** booktabs +This block can be used to wrap a table in the latex =booktabs= +environment, it takes the following arguments -- all but the first two +are optional. +| arg | description | +|-------+--------------------------------------------| +| table | a reference to the table | +| align | optional alignment string | +| env | optional environment, default to "tabular" | +| width | optional width specification string | + +#+srcname: booktabs +#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var align='() :var env="tabular" :var width='() :noweb yes :results latex + (flet ((to-tab (tab) + (orgtbl-to-generic + (mapcar (lambda (lis) + (if (listp lis) + (mapcar (lambda (el) + (if (stringp el) + el + (format "%S" el))) lis) + lis)) tab) + (list :lend " \\\\" :sep " & " :hline "\\hline")))) + (org-fill-template + " + \\begin{%env}%width%align + \\toprule + %table + \\bottomrule + \\end{%env}\n" + (list + (cons "env" (or env "table")) + (cons "width" (if width (format "{%s}" width) "")) + (cons "align" (if align (format "{%s}" align) "")) + (cons "table" + ;; only use \midrule if it looks like there are column headers + (if (equal 'hline (second table)) + (concat (to-tab (list (first table))) + "\n\\midrule\n" + (to-tab (cddr table))) + (to-tab table)))))) +#+end_src + +*** longtable This block can be used to wrap a table in the latex =longtable= environment, it takes the following arguments -- all but the first two are optional. @@ -113,7 +157,7 @@ are optional. | lastfoot | optional "lastfoot" string | #+srcname: longtable -#+begin_src emacs-lisp :var table='((:table)) :var env="table" :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex +#+begin_src emacs-lisp :var table='((:table)) :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex (org-fill-template " \\begin{longtable}%width%align