emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: latex export and booktabs tables
Date: Tue, 29 Jun 2010 10:10:18 -0700	[thread overview]
Message-ID: <87vd91aexy.fsf@gmail.com> (raw)
In-Reply-To: 457FCE1D-740F-4AA3-9913-E6D5117029E1@tsdye.com

Hi Tom,

How about the following proposed library of babel function which
constructs a booktabs environment using a toprule, (conditionally) a
midrule, and a bottomrule.

--8<---------------cut here---------------start------------->8---
*** 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
--8<---------------cut here---------------end--------------->8---

once loaded it can be applied as here

--8<---------------cut here---------------start------------->8---
** booktabs
#+tblname: months
| num | Abbrev. |
|-----+---------|
|   1 | Jan.    |
|   2 | Feb.    |
|   3 | Mar.    |

#+call: booktabs(table=months, align="r|l") :results latex :exports results
--8<---------------cut here---------------end--------------->8---

Also, note that the longtable function currently in the library-of-babel
does allow for replacing the global default hline value.

I'm sure the above isn't perfect, however hopefully it is close enough
that you could recommend how to get the rest of the way there.

Thanks -- Eric

"Thomas S. Dye" <tsd@tsdye.com> writes:

> Hi Eric,
>
> This is neat, but it doesn't directly address the problem posed by the
> OP.
>
> Currently, the LaTeX exporter uses \hline for all the horizontal rules
> in a table.  Booktabs defines three rules of different thickness for
> use at the top of the table, after the column heads, and at the bottom
> of the table.  So, one would want a function that let each of the
> rules take a different value.  The default for each could be hline,
> giving the current behavior of the exporter.  Francesco Pizzolante set
> this out nicely a while back:
> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg18311.html in a
> message that Seb Vauban brought up in a slightly different  context.
>
> All the best,
> Tom
>
> On Jun 27, 2010, at 7:09 PM, Eric Schulte wrote:
>
>> One way to deal with this without adding even more complexity to the
>> core of org-mode could be through the use of "Library of Babel"
>> functions.
>>
>> The attached org-mode file provides a function for exporting to the
>> longtable environment with some example usage.  If this looks
>> generally
>> useful it (and maybe similar functions) could be added to the
>> library of
>> babel distributed w/Org-mode.
>>
>> What do you think? -- Eric
>>
>> <longtable.org>
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>>
>>> Hi Erik,
>>>
>>> Erik Butz wrote:
>>>> I found a very old thread on the list about using the booktabs
>>>> package to
>>>> have nicer tables in latex export.
>>>>
>>>> I found that, making the changes below I can use the booktab
>>>> package to
>>>> export tables, and using standard tables only, this seems to work
>>>> fine.
>>>>
>>>> Can anyone advice on whether this kind of change is meaningful or
>>>> if this is
>>>> likely to introduce difficulties elsewhere which I did not
>>>> experience due to
>>>> the limited scope of usage? It should be said that I did not at
>>>> all look
>>>> into longtables so far.
>>>
>>> While trying to improve this, I think one could extend it so that
>>> the table
>>> environment can be changed as well, from `tabular' to `array',
>>> tabular*',
>>> `tabularx' or any other.
>>>
>>> There was a discussion on this, a while ago, by Francesco
>>> Pizzolante. Have a
>>> read at:
>>> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg18311.html
>>> .
>>>
>>> Best regards,
>>>  Seb
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-06-29 18:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22 21:36 latex export and booktabs tables Erik Butz
2010-06-22 23:03 ` Thomas S. Dye
2010-06-23  8:23 ` Sébastien Vauban
2010-06-28  5:09   ` Eric Schulte
2010-06-28  6:05     ` Carsten Dominik
2010-06-28  8:45       ` Sébastien Vauban
2010-06-28 15:16         ` Eric Schulte
2010-06-28 20:07           ` Erik Butz
2010-06-28 20:14           ` Sébastien Vauban
2010-06-29  8:00     ` Thomas S. Dye
2010-06-29 17:10       ` Eric Schulte [this message]
2010-06-30  3:01         ` Thomas S. Dye
2010-06-30 18:54         ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vd91aexy.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).