Skip to content

Commit

Permalink
BUG: Fix to_latex with longtable (#17959)
Browse files Browse the repository at this point in the history
pandas.DataFrame.to_latex(longtable=True) always contained
\multicolumn{3}{r}{{Continued on next page}}
regardless of the number of columns in the output.
  • Loading branch information
syxolk committed Oct 25, 2017
1 parent e1dabf3 commit 7a71573
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ I/O
- Bug in :meth:`DataFrame.to_html` in which there was no validation of the ``justify`` parameter (:issue:`17527`)
- Bug in :func:`HDFStore.select` when reading a contiguous mixed-data table featuring VLArray (:issue:`17021`)
- 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`)
- Bug in :meth:`DataFrame.to_latex` with ``longtable=True`` where a latex multicolumn always spanned over three columns (:issue:`17959`)

Plotting
^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ def get_col_type(dtype):
if self.longtable:
buf.write('\\endhead\n')
buf.write('\\midrule\n')
buf.write('\\multicolumn{3}{r}{{Continued on next '
'page}} \\\\\n')
buf.write('\\multicolumn{{{n}}}{{r}}{{{{Continued on next '
'page}}}} \\\\\n'.format(n=len(row)))
buf.write('\\midrule\n')
buf.write('\\endfoot\n\n')
buf.write('\\bottomrule\n')
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_to_latex_longtable(self, frame):
\midrule
\endhead
\midrule
\multicolumn{3}{r}{{Continued on next page}} \\
\multicolumn{2}{r}{{Continued on next page}} \\
\midrule
\endfoot
Expand Down

0 comments on commit 7a71573

Please sign in to comment.