Skip to content

Commit 6cd4145

Browse files
syxolkgfyoung
authored andcommitted
BUG: Fix to_latex with longtable (pandas-dev#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 ae74c2b commit 6cd4145

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ I/O
10891089
- Bug in :meth:`DataFrame.to_html` in which there was no validation of the ``justify`` parameter (:issue:`17527`)
10901090
- Bug in :func:`HDFStore.select` when reading a contiguous mixed-data table featuring VLArray (:issue:`17021`)
10911091
- Bug in :func:`to_json` where several conditions (including objects with unprintable symbols, objects with deep recursion, overlong labels) caused segfaults instead of raising the appropriate exception (:issue:`14256`)
1092+
- Bug in :meth:`DataFrame.to_latex` with ``longtable=True`` where a latex multicolumn always spanned over three columns (:issue:`17959`)
10921093

10931094
Plotting
10941095
^^^^^^^^

pandas/io/formats/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ def get_col_type(dtype):
962962
if self.longtable:
963963
buf.write('\\endhead\n')
964964
buf.write('\\midrule\n')
965-
buf.write('\\multicolumn{3}{r}{{Continued on next '
966-
'page}} \\\\\n')
965+
buf.write('\\multicolumn{{{n}}}{{r}}{{{{Continued on next '
966+
'page}}}} \\\\\n'.format(n=len(row)))
967967
buf.write('\\midrule\n')
968968
buf.write('\\endfoot\n\n')
969969
buf.write('\\bottomrule\n')

pandas/tests/io/formats/test_to_latex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test_to_latex_longtable(self, frame):
367367
\midrule
368368
\endhead
369369
\midrule
370-
\multicolumn{3}{r}{{Continued on next page}} \\
370+
\multicolumn{2}{r}{{Continued on next page}} \\
371371
\midrule
372372
\endfoot
373373

0 commit comments

Comments
 (0)