From 5599b0b32733fc869d8bf256a8feda06d9879749 Mon Sep 17 00:00:00 2001 From: John te Bokkel Date: Thu, 12 Feb 2026 22:19:01 -0800 Subject: [PATCH 1/2] feat: add caption to LongTable --- pylatex/table.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pylatex/table.py b/pylatex/table.py index fd1f2ded..6cf95f5a 100644 --- a/pylatex/table.py +++ b/pylatex/table.py @@ -496,6 +496,7 @@ class LongTable(Tabular): header = False foot = False lastFoot = False # noqa, casing is needed for backwards compatibility + caption = None def end_table_header(self): r"""End the table header which will appear on every page.""" @@ -530,6 +531,39 @@ def end_table_last_footer(self): self.append(Command("endlastfoot")) + def add_caption(self, caption): + """Add a caption to the float. + + Args + ---- + caption: str + The text of the caption. + """ + + self.caption = Command("caption", caption) + + def dumps_content(self, **kwargs): + r"""Represent the content of the tabular in LaTeX syntax. + + This adds the top and bottomrule when using a booktabs style tabular. + + Args + ---- + \*\*kwargs: + Arguments that can be passed to `~.dumps_list` + + Returns + ------- + string: + A LaTeX string representing the + """ + + content = "" + if self.caption is not None: + content += self.caption.dumps() + "%\n" + content += super().dumps_content(**kwargs) + return NoEscape(content) + class LongTabu(LongTable, Tabu): """A class that represents a longtabu (more flexible multipage table).""" From 957de63910e1cbe91140f3523880c8aebf06194d Mon Sep 17 00:00:00 2001 From: John te Bokkel Date: Thu, 12 Feb 2026 22:29:14 -0800 Subject: [PATCH 2/2] fix: missing line break after caption --- pylatex/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylatex/table.py b/pylatex/table.py index 6cf95f5a..13c1b63e 100644 --- a/pylatex/table.py +++ b/pylatex/table.py @@ -560,7 +560,7 @@ def dumps_content(self, **kwargs): content = "" if self.caption is not None: - content += self.caption.dumps() + "%\n" + content += self.caption.dumps() + "\\\\%\n" content += super().dumps_content(**kwargs) return NoEscape(content)