Skip to content

Commit 5f365ce

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 ba3a442 commit 5f365ce

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
@@ -954,8 +954,8 @@ def get_col_type(dtype):
954954
if self.longtable:
955955
buf.write('\\endhead\n')
956956
buf.write('\\midrule\n')
957-
buf.write('\\multicolumn{3}{r}{{Continued on next '
958-
'page}} \\\\\n')
957+
buf.write('\\multicolumn{{{n}}}{{r}}{{{{Continued on next '
958+
'page}}}} \\\\\n'.format(n=len(row)))
959959
buf.write('\\midrule\n')
960960
buf.write('\\endfoot\n\n')
961961
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)