* Patch to customize output of tables in LaTeX exporter.
@ 2011-10-28 17:09 Niels Giesen
2012-04-23 12:57 ` Bastien
0 siblings, 1 reply; 2+ messages in thread
From: Niels Giesen @ 2011-10-28 17:09 UTC (permalink / raw)
To: Orgmode
[-- 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/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Patch to customize output of tables in LaTeX exporter.
2011-10-28 17:09 Patch to customize output of tables in LaTeX exporter Niels Giesen
@ 2012-04-23 12:57 ` Bastien
0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2012-04-23 12:57 UTC (permalink / raw)
To: Niels Giesen; +Cc: Orgmode
Niels Giesen <niels.giesen@gmail.com> writes:
> 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
Finally applied, thanks.
--
Bastien
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-23 13:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-28 17:09 Patch to customize output of tables in LaTeX exporter Niels Giesen
2012-04-23 12:57 ` Bastien
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.