[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Create a longtable in LaTeX from orgtbl
From: |
Tak Kunihiro |
Subject: |
Re: [O] Create a longtable in LaTeX from orgtbl |
Date: |
Sat, 11 Oct 2014 15:25:40 +0900 (JST) |
http://lists.gnu.org/archive/html/emacs-orgmode/2014-06/msg00634.html
Thank you for responses in regard to making a longtable using a radio
table. I found a way and want to let you know.
\begin{footnotesize}
\begin{center}
% BEGIN RECEIVE ORGTBL tbl:greate-results
% END RECEIVE ORGTBL tbl:greate-results
\iffalse
#+ORGTBL: SEND tbl:greate-results orgtbl-to-latex-long :no-escape t
|------------+---------+---------|
| date | session | remarks |
|------------+---------+---------|
| 2014-10-11 | s141011 | foo |
|------------+---------+---------|
\fi
\end{center}
\end{footnotesize}
(defun orgtbl-to-latex-long (table params)
"Convert the orgtbl-mode TABLE to long TABLE in LaTeX."
(let* ((alignment (mapconcat (lambda (x) (if x "r" "l"))
org-table-last-alignment ""))
(params-common (list
:lstart " " :lend " \\\\" :sep " & "
:efmt "%s\\,(%s)" :hline " \\hline"))
(params0 (list
:tstart (concat " \\begin{longtable}{ " alignment " }\n"
" \\caption{" (orgtbl-util-last-latex
"caption") "}\\\\ % 1ST HEADER")
:tend (concat " \\endfirsthead\n"
" \\caption{Continued}\\\\ % 2ND
HEADER")))
(params2 (list
:tstart (concat " \\endhead\n"
" % ----------------")
:tend (concat " % ----------------\n"
" \\label{" (orgtbl-util-last-latex
"label") "}\n"
" \\end{longtable}")))
(table-head (list (car table))) ; store 1st row
(table-body (cdr table))
head0 head1 body
*table-head-rtn*)
;; look for hline as head-body separator
(when (memq 'hline table-body)
(setq *table-head-rtn* (reverse table-head)) ; to use `push' instead of
`append'
(while (not (eq 'hline (car table-body))) ; check for 2nd+ row
(push (car table-body) *table-head-rtn*)
(pop table-body))
(push 'hline *table-head-rtn*)
(pop table-body)
(setq table-head (reverse *table-head-rtn*)))
;; create text
(setq head0 (orgtbl-to-generic table-head (org-combine-plists params-common
params0 params)))
(setq head1 (orgtbl-to-generic table-head (org-combine-plists params-common
params)))
(setq body (orgtbl-to-generic table-body (org-combine-plists params-common
params2 params)))
(concat head0 "\n" head1 "\n" body)))
(defun orgtbl-util-last-latex (command)
"Go backward until `begin{longtable}' or beginning of current
buffer and obtain first content in curly bracket of COMMAND."
(save-excursion
(let* ((end (point))
(start (or (search-backward "begin{longtable}" nil t) (point-min)))
(string-to-search (buffer-substring start end)))
(string-match (concat "\\" command "{\\([^}]*\\)}") string-to-search)
(match-string 1 string-to-search))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [O] Create a longtable in LaTeX from orgtbl,
Tak Kunihiro <=