emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Create a longtable in LaTeX from orgtbl
@ 2014-06-17 23:11 Tak Kunihiro
  2014-06-18 12:58 ` Oliver Kappel
  2014-06-18 13:55 ` Oliver Kappel
  0 siblings, 2 replies; 6+ messages in thread
From: Tak Kunihiro @ 2014-06-17 23:11 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: tkk

Dear all,

Can you show how to create a longtable in LaTeX from orgtbl?

When a table in short, I create a LaTeX table in following way, as
demonstrated in manual.

https://www.gnu.org/software/emacs/manual/html_node/org/A-LaTeX-example.html

#+BEGIN_SRC LaTeX
\begin{table}[htdp]
  \begin{center}
    \caption{My great results}
    % BEGIN RECEIVE ORGTBL tbl:my-short-table
    % END RECEIVE ORGTBL tbl:my-short-table
    \iffalse
    #+ORGTBL: SEND tbl:my-short-table orgtbl-to-latex :no-escape t
    |------------+---------+--------|
    |       date | session | remark |
    |------------+---------+--------|
    | 2014-06-18 | s140618 |        |
    |------------+---------+--------|
    \fi
    \label{tbl:my-short-table}
  \end{center}
\end{table}
#+END_SRC


For longtable, I do in following way.  It barely works, but I have to
copy and paste header every time orgtbl is tossed to RECEIVE.

Can you show how to create a longtable in LaTeX from orgtbl?  Thank
you in advance.

Tak


#+BEGIN_SRC LaTeX
%% \usepackage{longtable}
\begin{center}
  \begin{longtable}{ rll }
    \caption{My great results}\\
    \hline
    % --- for 1st page ---
    date & session & remarks \\
    % --------------------
    \hline
    \endfirsthead
    \caption{Continued}\\
    \hline
    % --- for 2nd+ page --
    date & session & remarks \\
    % --------------------
    \hline
    \endhead
    % --------------------
    % BEGIN RECEIVE ORGTBL tbl:my-long-table
    % END RECEIVE ORGTBL tbl:my-long-table
    \iffalse
    #+ORGTBL: SEND tbl:my-long-table orgtbl-to-longtbl :no-escape t :splice nil :skip 0
    | %     date | session | remarks |
    | 2014-06-18 | s140618 | foo     |
    \fi
    % --------------------
    \hline
    \label{tbl:my-long-table}
  \end{longtable}
\end{center}
#+END_SRC

#+BEGIN_SRC emacs-lisp
(defun orgtbl-to-longtbl (table params)
  "Convert the Orgtbl mode TABLE to LaTeX."
  (let* ((alignment (mapconcat (lambda (x) (if x "r" "l"))
                               org-table-last-alignment ""))
         (params2
          (list
           :tstart (concat "%     \\begin{longtable}{ " alignment " }")
           :lstart "" :lend " \\\\" :sep " & "
           :efmt "%s\\,(%s)" :hline "\\hline")))
    (orgtbl-to-generic table (org-combine-plists params2 params))))
#+END_SRC

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Create a longtable in LaTeX from orgtbl
@ 2014-10-11  6:25 Tak Kunihiro
  0 siblings, 0 replies; 6+ messages in thread
From: Tak Kunihiro @ 2014-10-11  6:25 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: tak.kunihiro

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))))

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-11  6:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17 23:11 Create a longtable in LaTeX from orgtbl Tak Kunihiro
2014-06-18 12:58 ` Oliver Kappel
2014-06-18 13:55 ` Oliver Kappel
2014-06-18 14:33   ` Nick Dokos
2014-06-18 17:40     ` Oliver Kappel
  -- strict thread matches above, loose matches on Subject: below --
2014-10-11  6:25 Tak Kunihiro

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).