Right. I thik I found it....


On 06/09/2026 07:53, Ihor Radchenko wrote:
"Pedro A. Aranda" <[email protected]> writes:

Hi

the \\ is indeed needed for some tables. Look at the attached screenshots.

On 05/09/2026 17:55, Ihor Radchenko wrote:
#+ATTR_LATEX: :environment longtabu  :align {|l|l|}
#+NAME: 1
| 100 | test |

Got it, but can we somehow distinguish between the two cases and write
\\ in one scenario (with caption) and do not write \\ in another?


--
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: Pedro A Aranda <[email protected]>
Date: Sun, 06 Sep 2026 10:09:26 +0200
Subject: ox-latex.el: Only emit extra line when caption is present.

* lisp/ox-latex.el (org-latex--org-table): Add a double backslash (extra
line) only when a caption is present.
* 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              |  2 ++
 testing/lisp/test-ox-latex.el | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9e7b52306..93a4476d4 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4304,10 +4304,12 @@ (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)
+                     (string-prefix-p "\\caption{" caption)
 		     (concat caption "\\\\\n"))
 		contents
 		(and (not above?)
 		     (org-string-nw-p caption)
+                     (string-prefix-p "\\caption{" caption)
 		     (concat caption "\\\\\n"))
 		(format "\\end{%s}" table-env)
 		(and fontsize "}"))))
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 9cd83d509..59f316cfa 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -173,5 +173,34 @@ (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."

Reply via email to