emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: org-table latex export does not honour alignment [7.5]
@ 2011-09-07  5:01 Arik Mitschang
  2011-09-07  7:46 ` Eric S Fraga
  0 siblings, 1 reply; 4+ messages in thread
From: Arik Mitschang @ 2011-09-07  5:01 UTC (permalink / raw)
  To: emacs-orgmode

When exporting a file to latex, the alignment of tables within that file
specified via the in-table <l>,<c> or <r> fields are not honoured. For
example:

|-------------+----------+----------+----------+----------|
|-------------+----------+----------+----------+----------|
| long header | header a | header b | header c | header d |
|-------------+----------+----------+----------+----------|
| <l>         | <l>      |      <r> |      <r> |      <r> |
| 1           | 2        |        3 |        4 |        5 |
| 6           | 7        |        8 |        9 |       10 |
| /           | >        |          |          |          |


should have the first two columns left-aligned and the last three right
aligned. The vertical line in the table above is present. This also is
the case when forcing a table environment via #+CAPTION. The table above
generates the tabular command:

\begin{tabular}{rr|rrr}

Where it should generate:

\begin{tabular}{ll|rrr}

Interestingly, when doing a

M-x org-table-export

The alignment is find, but the vertical line is present. Also, it
appears that ASCII also does not honour the alignment but HTML export
does (including the <c>).


Thanks,
-Arik



Emacs  : GNU Emacs 23.3.1 (x86_64-apple-darwin10.5.0, GTK+ Version 2.18.9)
 of 2011-06-07 on nobunaga.local
Package: Org-mode version 7.5

current state:
==============
(setq
 org-log-done t
 org-export-latex-default-class "simple"
 org-file-apps '((auto-mode . emacs) ("\\.mm\\'" . default) ("\\.x?html'" . system) ("pdf" . system))
 org-export-with-LaTeX-fragments 'dvipng
 org-export-latex-after-initial-vars-hook '(org-beamer-after-initial-vars)
 org-hide-block-startup t
 org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook)
 org-agenda-custom-commands '(("l" "Reading list" tags-todo "L/TODO" nil) ("t" "todo items" tags-todo "-L-P/TODO" nil) ("p" "Project todo items" tags "P/TODO" nil)
			      ("A" "All APPTs" todo "APPT" nil) ("i" "INIT items" todo "INIT" nil))
 org-agenda-files '("~/org/")
 org-agenda-tags-column 95
 org-babel-load-languages '((emacs-lisp . t) (python . t) (ditaa \.t) (R . t) (sh . t))
 org-clock-into-drawer t
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-capture-templates '(("l" "add to reading list" entry (file+headline "~/org/main.org" "Reading list") "* TODO READ: [[%^{Article URL}]] :L:" :immediate-finish t)
			 ("a" "appointment" entry (file+headline "~/org/main.org" "TASKS") "* APPT %^{Task description} %^g\n  %^t\n  Location: %^{Location}"
			  :immediate-finish t)
			 ("r" "reminder (no time)" entry (file+headline "~/org/main.org" "TASKS") "* TODO %^{Task description}" :immediate-finish t)
			 ("n" "README note" entry (function awm-org-capture-get-readme-note) "* %U\n  %?"))
 org-after-todo-state-change-hook '(org-clock-out-if-current awm-org-agenda-to-appt-activate)
 org-babel-tangle-lang-exts '(("python" . "py") ("emacs-lisp" . "el"))
 org-capture-after-finalize-hook '(awm-org-agenda-to-appt-activate)
 org-export-blocks-postblock-hook '(org-exp-res/src-name-cleanup)
 org-export-html-postamble t
 org-export-html-style "<link rel='stylesheet' type='text/css' href='./style.css'/>"
 org-export-latex-format-toc-function 'org-export-latex-format-toc-default
 org-latex-to-pdf-process '("latex -interaction nonstopmode -output-directory %o %f" "bibtex %b" "latex -interaction nonstopmode -output-directory %o %f"
			    "latex -interaction nonstopmode -output-directory %o %f" "dvipdf %b.dvi" "rm %b.bbl %b.blg %b.tex %b.dvi")
 org-tab-first-hook '(org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe)
 org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer)
 org-confirm-shell-link-function 'yes-or-no-p
 org-export-first-hook '(org-beamer-initialize-open-trackers)
 org-export-with-toc nil
 org-highlight-sparse-tree-matches nil
 org-todo-keywords '((sequence "TODO(t)" "APPT(a)" "WAIT(w@)" "PROJ(p)" "INIT(i!)" "|" "DONE(d)" "CNCL(c@)"))
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-export-html-postamble-format '(("en" "<p class=\"author\">Author: %a</p>\n<p class=\"date\">Date: %d</p>"))
 org-n-level-faces 4
 org-babel-pre-tangle-hook '(save-buffer)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-show-empty-lines org-optimize-window-after-visibility-change)
 org-export-latex-classes '(("article" "\\documentclass[11pt]{article}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")
			     ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}")
			     ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
			    ("report" "\\documentclass[11pt]{report}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}")
			     ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
			    ("book" "\\documentclass[11pt]{book}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}")
			     ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
			    ("beamer" "\\documentclass{beamer}" org-beamer-sectioning)
			    ("beamerposter" "\\documentclass{beamer}\n[NO-DEFAULT-PACKAGES][PACKAGES]" org-beamer-sectioning)
			    ("simple"
			     "\\documentclass[11pt]{article}\n\n\\setlength{\\oddsidemargin}{0.25in}\n\\setlength{\\evensidemargin}{0.25in}\n\\setlength{\\textwidth}{6in}\n\\setlength{\\topmargin}{0.1in}\n\\setlength{\\headsep}{0.2in}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\\usepackage{natbib}\n\\usepackage{astroj}\n[NO-DEFAULT-PACKAGES][PACKAGES]"
			     ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
			     ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
			    )
 org-publish-project-alist '(("MQ-web" :base-directory "~/org/mqweb/" :auto-index t :index-filename "sitemap.org" :recursive t :makeindex t :publishing-directory
			      "/verus.science:~/html/")
			     )
 org-export-preprocess-before-normalizing-links-hook '(org-remove-file-link-modifiers)
 org-mode-hook '(org-babel-result-hide-spec org-babel-hide-all-hashes auto-fill-mode (lambda nil (local-set-key "\333Z" (quote org-global-cycle))))
 org-cycle-include-plain-lists nil
 org-export-latex-image-default-option "width=\\textwidth"
 org-refile-targets '((org-agenda-files :maxlevel . 900))
 org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point org-babel-execute-safely-maybe)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-footnote-auto-adjust t
 org-export-interblocks '((lob org-babel-exp-lob-one-liners) (src org-babel-exp-inline-src-blocks))
 org-link-mailto-program '(vm-mail-to-mailto-url "mailto:%a?subject=%s")
 org-occur-hook '(org-first-headline-recenter)
 org-from-is-user-regexp "\\<Arik Mitschang\\>"
 org-export-preprocess-before-selecting-backend-code-hook '(org-beamer-select-beamer-code)
 org-confirm-babel-evaluate nil
 org-tags-column 80
 org-columns-default-format "%8CATEGORY %25ITEM(Description) %TODO(Type) %3PRIORITY %6Effort{:} %6CLOCKSUM(CT) %ALLTAGS"
 org-export-latex-final-hook '(org-beamer-amend-header org-beamer-fix-toc org-beamer-auto-fragile-frames org-beamer-place-default-actions-for-lists)
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-export-blocks '((src org-babel-exp-src-block nil) (comment org-export-blocks-format-comment t) (ditaa org-export-blocks-format-ditaa nil)
		     (dot org-export-blocks-format-dot nil))
 )

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: org-table latex export does not honour alignment [7.5]
  2011-09-07  5:01 Bug: org-table latex export does not honour alignment [7.5] Arik Mitschang
@ 2011-09-07  7:46 ` Eric S Fraga
  2011-09-08  7:02   ` Arik Mitschang
  0 siblings, 1 reply; 4+ messages in thread
From: Eric S Fraga @ 2011-09-07  7:46 UTC (permalink / raw)
  To: emacs-orgmode

Arik Mitschang <arik.mitschang@gmail.com> writes:

> When exporting a file to latex, the alignment of tables within that file
> specified via the in-table <l>,<c> or <r> fields are not honoured. For
> example:
>
> |-------------+----------+----------+----------+----------|
> |-------------+----------+----------+----------+----------|
> | long header | header a | header b | header c | header d |
> |-------------+----------+----------+----------+----------|
> | <l>         | <l>      |      <r> |      <r> |      <r> |
> | 1           | 2        |        3 |        4 |        5 |
> | 6           | 7        |        8 |        9 |       10 |
> | /           | >        |          |          |          |
>
>
> should have the first two columns left-aligned and the last three right
> aligned. The vertical line in the table above is present. This also is
> the case when forcing a table environment via #+CAPTION. The table above
> generates the tabular command:
>
> \begin{tabular}{rr|rrr}
>
> Where it should generate:
>
> \begin{tabular}{ll|rrr}

You can specify the alignment for latex export directly if you put this
line before the table itself:

  #+attr_latex: align=ll|rrr

cf. (org) Tables in LaTeX export,

[[info:org#Tables%20in%20LaTeX%20export][info:org#Tables in LaTeX export]]

HTH,
eric
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.7 (release_7.7.257.g0dd1)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: org-table latex export does not honour alignment [7.5]
  2011-09-07  7:46 ` Eric S Fraga
@ 2011-09-08  7:02   ` Arik Mitschang
  2011-09-08  9:02     ` Eric S Fraga
  0 siblings, 1 reply; 4+ messages in thread
From: Arik Mitschang @ 2011-09-08  7:02 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Thanks for the response. Yes, I'm aware of that, but it seems unnecessary when I
have already used the alignments in the table (and of course if you want HTML to
be the same alignment as latex then you would have to do both). I have a patch
that fixes this issue and behaves the same when alignment is not specified (or
is specified via the attr_latex). This patch is actually against org version
7.7. Not totally sure the best delivery method, but it is short so I include
here. Let me know what you think

Thanks,
-Arik

==========================================

diff -U3 /usr/local/share/emacs/site-lisp/org-latex.el
/Users/arikm/devel/org-latex-table-export-align-fix.el
--- /usr/local/share/emacs/site-lisp/org-latex.el	2011-07-28 20:35:40.000000000
+1000
+++ /Users/arikm/devel/org-latex-table-export-align-fix.el	2011-09-08
16:31:32.000000000 +1000
@@ -1867,9 +1867,11 @@
              (org-table-last-alignment (copy-sequence org-table-last-alignment))
              (org-table-last-column-widths (copy-sequence
                                             org-table-last-column-widths))
+	     (forced-aligns (org-find-text-property-in-string 
+			     'org-forced-aligns raw-table))
              fnum fields line lines olines gr colgropen line-fmt align
-             caption width shortn label attr floatp placement
-	     longtblp tblenv tabular-env)
+             alignments caption width shortn label attr floatp
+             placement longtblp tblenv tabular-env)
         (if org-export-latex-tables-verbatim
             (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
                                 "\\end{verbatim}\n")))
@@ -1944,12 +1946,21 @@
             (when (and (not org-export-latex-tables-column-borders)
                        (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
               (setq line-fmt (match-string 2 line-fmt)))
+	    ;; incorporate forced alignment defaulting to "right" alignment
+	    (dotimes (i (length fields))
+	      (let ((forced forced-aligns)
+		    (a "r"))
+		(while forced
+		  (when (= (car (car forced)) (- (length fields) i))
+		    (setq a (cdr (car forced))))
+		  (setq forced (cdr forced)))
+		(push a alignments)))
             ;; format alignment
             (unless align
               (setq align (apply 'format
                                  (cons line-fmt
-                                       (mapcar (lambda (x) (if x "r" "l"))
-                                               org-table-last-alignment)))))
+                                       (mapcar (lambda (x) x)
+					       alignments)))))
             ;; prepare the table to send to orgtbl-to-latex
             (setq lines
                   (mapcar

=============================================

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: org-table latex export does not honour alignment [7.5]
  2011-09-08  7:02   ` Arik Mitschang
@ 2011-09-08  9:02     ` Eric S Fraga
  0 siblings, 0 replies; 4+ messages in thread
From: Eric S Fraga @ 2011-09-08  9:02 UTC (permalink / raw)
  To: Arik Mitschang; +Cc: emacs-orgmode

Arik Mitschang <arik.mitschang@gmail.com> writes:

> Hi Eric,
>
> Thanks for the response. Yes, I'm aware of that, but it seems unnecessary when I
> have already used the alignments in the table (and of course if you
> want HTML to

I agree but at least there's a workaround.

> be the same alignment as latex then you would have to do both). I have a patch
> that fixes this issue and behaves the same when alignment is not specified (or
> is specified via the attr_latex). This patch is actually against org version
> 7.7. Not totally sure the best delivery method, but it is short so I include
> here. Let me know what you think

I'll leave this for others more capable in patching etc.!
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.7 (release_7.7.261.g2178)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-08  9:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-07  5:01 Bug: org-table latex export does not honour alignment [7.5] Arik Mitschang
2011-09-07  7:46 ` Eric S Fraga
2011-09-08  7:02   ` Arik Mitschang
2011-09-08  9:02     ` Eric S Fraga

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).