[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Re: latex export and booktabs tables

From: Eric Schulte
Subject: Re: [Orgmode] Re: latex export and booktabs tables
Date: Tue, 29 Jun 2010 10:10:18 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

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)
                  (mapcar (lambda (lis)
                            (if (listp lis)
                                (mapcar (lambda (el)
                                          (if (stringp el)
                                            (format "%S" el))) lis)
                              lis)) tab)
                  (list :lend " \\\\" :sep " & " :hline "\\hline"))))
      (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)))
                        (to-tab (cddr table)))
              (to-tab table))))))
--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" <address@hidden> 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/address@hidden/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 <address@hidden> 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/address@hidden/msg18311.html
>>> .
>>> Best regards,
>>>  Seb
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> address@hidden
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

reply via email to

[Prev in Thread] Current Thread [Next in Thread]