Try this patch...
On 06/09/2026 14:17, Ihor Radchenko wrote:
"Pedro A. Aranda" <[email protected]> writes:
Right. I thik I found it....
(and above?
(org-string-nw-p caption)
+ (string-prefix-p "\\caption{" caption)
(concat caption "\\\\\n"))
When caption is not present, this will print nothing (e.g. no label when
only label should be present).
Try with the original reproducer. You will see that there will be latex
errors with your patch.
--
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 b88816123bc40a62a6fb8e6b6864b35f8b837dc6 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Sun, 6 Sep 2026 20:02:38 +0200
Subject: [PATCH] Only emit extra line when caption above table is present.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lisp/ox-latex.el (org-latex--org-table): Add a double backslash (extra
line) only when a caption is present and placed above the table.
* testing/lisp/test-ox-latex.el (test-ox-latex/table-no-caption):
New test to check that the double backslash is added correctly.
Reported-by: Aurélien Francillon
Link: https://list.orgmode.org/ZvSBf2tBM4Udws9l@crashtoo/
---
lisp/ox-latex.el | 8 ++++++--
testing/lisp/test-ox-latex.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9e7b52306..bdcafbe14 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4304,11 +4304,15 @@ (defun org-latex--org-table (table contents info)
(format "\\begin{%s}%s{%s}\n" table-env width alignment)
(and above?
(org-string-nw-p caption)
- (concat caption "\\\\\n"))
+ caption)
+ (and above?
+ (org-string-nw-p caption)
+ (string-prefix-p "\\caption{" caption)
+ "\\\\\n")
contents
(and (not above?)
(org-string-nw-p caption)
- (concat caption "\\\\\n"))
+ caption)
(format "\\end{%s}" table-env)
(and fontsize "}"))))
(t
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 9cd83d509..6a0e1d781 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -173,6 +173,36 @@ (ert-deftest test-ox-latex/table-el-table ()
\\end{tabular}"
))))
+(ert-deftest test-ox-latex/table-no-caption ()
+ "Test that only captions add a double backslash."
+ (org-test-with-exported-text
+ 'latex
+ "#+LATEX_HEADER: \\usepackage{tabu}
+
+This is a test.
+
+#+ATTR_LATEX: :environment longtabu :align |l|l|
+#+NAME: 1
+#+CAPTION: This is table 1
+| 100 | test |
+
+#+ATTR_LATEX: :environment longtabu :align |l|l|
+#+NAME: 1
+| 100 | test |
+"
+ (goto-char (point-min))
+ (should (search-forward-regexp "^\\\\begin{longtabu}"))
+ (should (search-forward-regexp "^\\\\caption{"))
+ (should (search-forward-regexp "^\\\\\\\\"))
+ (should (search-forward-regexp "^100 & test"))
+ (should (search-forward-regexp "^\\\\begin{longtabu}"))
+ (save-excursion
+ (should-not (search-forward-regexp "^\\\\caption{" nil t)))
+ (save-excursion
+ (should-not (search-forward-regexp "^\\\\\\\\" nil t)))
+ (should (search-forward-regexp "^100 & test"))))
+
+
(ert-deftest test-ox-latex/inline-image ()
"Test inline images."
(org-test-with-exported-text
--
2.43.0