Skip to content

Commit ce67f8d

Browse files
Backport PR #46057: bug: styler latex longtable column count (#46157)
1 parent 4020088 commit ce67f8d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v1.4.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Fixed regressions
2323

2424
Bug fixes
2525
~~~~~~~~~
26-
-
26+
- Fixed "longtable" formatting in :meth:`.Styler.to_latex` when ``column_format`` is given in extended format (:issue:`46037`)
2727
-
2828

2929
.. ---------------------------------------------------------------------------

pandas/io/formats/templates/latex_longtable.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
{% if midrule is not none %}
6060
\{{midrule}}
6161
{% endif %}
62-
\multicolumn{% raw %}{{% endraw %}{{column_format|length}}{% raw %}}{% endraw %}{r}{Continued on next page} \\
62+
\multicolumn{% raw %}{{% endraw %}{{body[0]|length}}{% raw %}}{% endraw %}{r}{Continued on next page} \\
6363
{% if midrule is not none %}
6464
\{{midrule}}
6565
{% endif %}

pandas/tests/io/formats/style/test_to_latex.py

+7
Original file line numberDiff line numberDiff line change
@@ -990,3 +990,10 @@ def test_clines_multiindex(clines, expected, env):
990990
styler.hide(level=1)
991991
result = styler.to_latex(clines=clines, environment=env)
992992
assert expected in result
993+
994+
995+
def test_col_format_len(styler):
996+
# gh 46037
997+
result = styler.to_latex(environment="longtable", column_format="lrr{10cm}")
998+
expected = r"\multicolumn{4}{r}{Continued on next page} \\"
999+
assert expected in result

0 commit comments

Comments
 (0)