Hi,

a small patch attached that allows you to pass the :align attribute to table.el tables

Best, /PA
--
Pedro A. Aranda
ox-latex & ox-beamer maintainer

Sagen's Paradeiser! (ORF: Als Radiohören gefährlich war) => write BE!
IA: onomatopeya del rebuzno
2nd year of the New Koprocracy
From 2679422e889f957dc0e7f169f06e5a2027dcdc36 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Mon, 5 Oct 2026 18:08:28 +0200
Subject: [PATCH 55/55] ox-latex: pass :align to table.el tables

* doc/org-manual.org (*** Tables in LaTeX export): Mention explicitly
that "table.el" tables accept the ':align' attribute.
* lisp/ox-latex.el (org-latex--table.el-table): Replace default
alignment specification produced by with the ':align' attribute if
present.
* testing/lisp/test-ox-latex.el (test-ox-latex/table-el-align): New test
to check that the ':align' attribute is passed to "table.el" tables.
---
 doc/org-manual.org            |  3 ++-
 lisp/ox-latex.el              |  8 ++++++++
 testing/lisp/test-ox-latex.el | 19 +++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 1a6295593..3ad2b96d6 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14866,7 +14866,8 @@ include:
 - =:align=, =:font=, =:width= ::
 
   The LaTeX export backend uses these attributes for regular tables
-  to set their alignments, fonts, and widths.
+  to set their alignments, fonts, and widths. "table.el" tables accept
+  the =:align= attribute.
 
 - =:options= ::
 
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4e62fe245..b1ee3eea2 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4962,6 +4962,14 @@ (defun org-latex--table.el-table (table info)
     (let ((attr (org-export-read-attribute :attr_latex table))
 	  (caption (org-latex--caption/label-string table info))
 	  (above? (org-latex--caption-above-p table info)))
+      (when-let* ((new-alignment (plist-get attr :align)))
+        ;; The default alignment for table-el tables is l||l...
+        ;; Replace with the alignment specified in the document.
+        (save-match-data
+          (when (string-match "\\(\\\\begin{[^}]+?}{\\)[^}]+?}" output)
+            (let ((orig-str (match-string 0 output))
+                  (newstr (concat (match-string 1 output) new-alignment "}")))
+              (setq output (string-replace orig-str newstr output))))))
       (when (plist-get attr :rmlines)
 	;; When the "rmlines" attribute is provided, remove all hlines
 	;; but the one separating heading from the table body.
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index d104d1ae8..ebade8930 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -1247,5 +1247,24 @@ (ert-deftest test-ox-latex/fancy-listings ()
     (should (search-forward "\\end{document}"))
     )))
 
+(ert-deftest test-ox-latex/table-el-align ()
+  "Check that the :align parameter is passed to table.el tables."
+  (org-test-with-exported-text
+   'latex
+   "* The table.el table test
+
+#+ATTR_LATEX: :align |p{2cm}|c|c|
++-----+-----+-----+
+| Col1|   Joined  |
++-----+-----+-----+
+| 1   |  3  |  b  |
++-----+-----+-----+
+| 2   |  4  | a   |
++-----+-----+-----+
+"
+   ;; (message "table-el-align: %s" (buffer-string))
+   (goto-char (point-min))
+   (should (search-forward "\\begin{tabular}{|p{2cm}|c|c|}"))))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
-- 
2.53.0

Reply via email to