emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Niels Giesen <niels.giesen@gmail.com>
To: Orgmode <emacs-orgmode@gnu.org>
Subject: Patch to customize output of tables in LaTeX exporter.
Date: Fri, 28 Oct 2011 19:09:46 +0200	[thread overview]
Message-ID: <87ipn911r9.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

Dear list,

Attached is a patch that allows some customization of tables in LaTeX
export.

It adds three new customizable with default values:

  org-export-latex-tables-tstart : nil
  org-export-latex-tables-hline  : "\\hline"
  org-export-latex-tables-tend   : nil

These variables allows users to use e.g. the booktabs package (use
\\toprule, \\midrule and \\bottomrule for the respective variables above
- these are options you'll find in the defcustoms too) and create more
beautiful tables in LaTeX documents.

The patch also fixes the double rule after the table head when using a
longtable environment, as this 1) is ugly and 2) caused booktabs
longtables to go quite awry.

The patch does - save for the longtable fix - bring no change to the
export of existing code as long as the defaults are not changed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] to customize LaTeX output of tables (e.g. to use booktabs package) --]
[-- Type: text/x-diff, Size: 4547 bytes --]

From f2d9cf34b1b95c7e6941c8f9129ae9e32ba33444 Mon Sep 17 00:00:00 2001
From: Niels Giesen <niels.giesen@gmail.com>
Date: Thu, 27 Oct 2011 09:23:16 +0200
Subject: [PATCH] Add defcustoms for LaTeX export of table rules :tstart, :hline and :tend
 Fix double rule in longtable.

This allows users to use e.g. the booktabs package and create more
beautiful tables in LaTeX documents. Also fix double headline rules
when using a longtable environment, as this caused booktabs longtables
to go quite awry.

* lisp/org-latex.el:
New defcustoms and default values:

  org-export-latex-tables-tstart : nil
  org-export-latex-tables-hline  : "\\hline"
  org-export-latex-tables-tend   : nil

* lisp/org-table.el (orgtbl-to-generic): add check for :skipheadrule.
When present, the :hline following the head will be skipped. This is
necessary to avoid doubling of horizontal rules in LaTeX longtable
environments and consequent width problems.
---
 lisp/org-latex.el |   38 ++++++++++++++++++++++++++++++++++----
 lisp/org-table.el |    3 ++-
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 649e4a7..3e47359 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -369,6 +369,30 @@ When nil, grouping causes only separation lines between groups."
   :group 'org-export-latex
   :type 'boolean)
 
+(defcustom org-export-latex-tables-tstart nil
+  "LaTeX command for top rule for tables."
+  :group 'org-export-latex
+  :type '(choice
+          (const :tag "Nothing" nil)
+          (string :tag "String")
+          (const  :tag "Booktabs default: \\toprule" "\\toprule")))
+
+(defcustom org-export-latex-tables-hline "\\hline"
+  "LaTeX command to use for a rule somewhere in the middle of a table."
+  :group 'org-export-latex
+  :type '(choice
+          (string :tag "String")
+          (const  :tag "Standard: \\hline" "\\hline")
+          (const  :tag "Booktabs default: \\midrule" "\\midrule")))
+
+(defcustom org-export-latex-tables-tend nil
+  "LaTeX command for bottom rule for tables."
+  :group 'org-export-latex
+  :type '(choice
+          (const :tag "Nothing" nil)
+          (string :tag "String")
+          (const  :tag "Booktabs default: \\bottomrule" "\\bottomrule")))
+
 (defcustom org-export-latex-low-levels 'itemize
   "How to convert sections below the current level of sectioning.
 This is specified by the `org-export-headline-levels' option or the
@@ -1998,14 +2022,20 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 				    align))
                         (orgtbl-to-latex
                          lines
-                         `(:tstart nil :tend nil
+                         `(:tstart ,org-export-latex-tables-tstart
+				   :tend ,org-export-latex-tables-tend
+				   :hline ,org-export-latex-tables-hline
+                                   :skipheadrule ,longtblp
                                    :hlend ,(if longtblp
                                                (format "\\\\
-\\hline
+%s
 \\endhead
-\\hline\\multicolumn{%d}{r}{Continued on next page}\\
+%s\\multicolumn{%d}{r}{Continued on next page}\\
 \\endfoot
-\\endlastfoot" (length org-table-last-alignment))
+\\endlastfoot"
+                                           org-export-latex-tables-hline
+                                           org-export-latex-tables-hline
+                                           (length org-table-last-alignment))
                                              nil)))
                         (if (not longtblp) (format "\n\\end{%s}" tabular-env))
                         (if longtblp "\n" (if org-export-latex-tables-centered
diff --git a/lisp/org-table.el b/lisp/org-table.el
index edcdbe1..247f585 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4460,6 +4460,7 @@ directly by `orgtbl-send-table'.  See manual."
 
   (let* ((splicep (plist-get params :splice))
 	 (hline (plist-get params :hline))
+     (skipheadrule (plist-get params :skipheadrule))
 	 (remove-nil-linesp (plist-get params :remove-nil-lines))
 	 (remove-newlines (plist-get params :remove-newlines))
 	 (*orgtbl-hline* hline)
@@ -4505,7 +4506,7 @@ directly by `orgtbl-send-table'.  See manual."
 		 (*orgtbl-sep* (or (plist-get params :hlsep) *orgtbl-sep*))
 		 (*orgtbl-fmt* (or (plist-get params :hfmt) *orgtbl-fmt*)))
 	    (orgtbl-format-section 'hline))
-	  (if hline (push hline *orgtbl-rtn*))
+	  (if (and hline (not skipheadrule)) (push hline *orgtbl-rtn*))
 	  (pop *orgtbl-table*)))
 
     ;; Now format the main section.
-- 
1.7.4.1


[-- Attachment #3: Type: text/plain, Size: 45 bytes --]



Regards,
Niels.
-- 
http://pft.github.com/

             reply	other threads:[~2011-10-28 17:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28 17:09 Niels Giesen [this message]
2012-04-23 12:57 ` Patch to customize output of tables in LaTeX exporter Bastien

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=87ipn911r9.fsf@gmail.com \
    --to=niels.giesen@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).