Skip to content

Commit 970969b

Browse files
committed
BUG: Fix to_latex with longtable (#17959)
pandas.DataFrame.to_latex(longtable=True) always contained \multicolumn{3}{r}{{Continued on next page}} regardless of the number of columns in the output.
1 parent e1dabf3 commit 970969b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pandas/io/formats/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,8 @@ def get_col_type(dtype):
942942
if self.longtable:
943943
buf.write('\\endhead\n')
944944
buf.write('\\midrule\n')
945-
buf.write('\\multicolumn{3}{r}{{Continued on next '
946-
'page}} \\\\\n')
945+
buf.write('\\multicolumn{{{n}}}{{r}}{{{{Continued on next '
946+
'page}}}} \\\\\n'.format(n=len(row)))
947947
buf.write('\\midrule\n')
948948
buf.write('\\endfoot\n\n')
949949
buf.write('\\bottomrule\n')

pandas/tests/io/formats/test_to_latex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def test_to_latex_longtable(self, frame):
365365
\midrule
366366
\endhead
367367
\midrule
368-
\multicolumn{3}{r}{{Continued on next page}} \\
368+
\multicolumn{2}{r}{{Continued on next page}} \\
369369
\midrule
370370
\endfoot
371371

0 commit comments

Comments
 (0)