From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Thomas S. Dye" Subject: Re: Re: latex export and booktabs tables Date: Tue, 29 Jun 2010 17:01:47 -1000 Message-ID: <9B8B7117-24B4-4DC2-A335-579D7AB5601C@tsdye.com> References: <87tyouyx6b.fsf@mundaneum.com> <878w5zd9po.fsf@gmail.com> <457FCE1D-740F-4AA3-9913-E6D5117029E1@tsdye.com> <87vd91aexy.fsf@gmail.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=53894 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTnYi-0004VG-2b for emacs-orgmode@gnu.org; Tue, 29 Jun 2010 23:01:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTnYf-0007W3-9R for emacs-orgmode@gnu.org; Tue, 29 Jun 2010 23:01:55 -0400 Received: from oproxy2-pub.bluehost.com ([67.222.39.60]:52271) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OTnYe-0007Vh-VM for emacs-orgmode@gnu.org; Tue, 29 Jun 2010 23:01:53 -0400 In-Reply-To: <87vd91aexy.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org Hi Eric, Sweet! Here is a stripped-down version that integrates with the AucTeX =20 function, (LaTeX-environment ARG). --8<---------------cut here---------------start------------->8--- #+srcname: booktabs-2 #+begin_src emacs-lisp :var table=3D'((:head) hline (:body)) (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 " \\toprule %table \\bottomrule\n" (list (cons "table" ;; only use \midrule if it looks like there are column =20 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--- Here is an example of how I intend to use it. --8<---------------cut here---------------start------------->8--- #+srcname: test #+begin_src latex :noweb yes \begin{table}[htb!] \centering \caption{A test table} \label{tab:test} \begin{tabular}{rl} <> \end{tabular} \end{table} #+end_src --8<---------------cut here---------------end--------------->8--- Everything around the noweb reference was due to the AucTeX function. Thanks for the two Library of Babel functions. I'll be using them a =20 lot! All the best, Tom On Jun 29, 2010, at 7:10 AM, Eric Schulte wrote: > 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 =3Dbooktabs=3D > 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=3D'((:head) hline (:body)) :var =20 > align=3D'() :var env=3D"tabular" :var width=3D'() :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 =20 > 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=3Dmonths, align=3D"r|l") :results latex = :exports =20 > results > --8<---------------cut here---------------end--------------->8--- > > Also, note that the longtable function currently in the library-of-=20 > 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" writes: > >> Hi Eric, >> >> This is neat, but it doesn't directly address the problem posed by =20= >> the >> OP. >> >> Currently, the LaTeX exporter uses \hline for all the horizontal =20 >> 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 =20 >> 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 =20= >> 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 >>> >>> >>> S=E9bastien Vauban 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