Skip to content

Commit f19c157

Browse files
attack68feefladder
authored andcommitted
BUG: no label render in Styler.to_latex if caption and "longtable" (pandas-dev#43399)
1 parent c1e0a84 commit f19c157

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pandas/io/formats/templates/latex_longtable.tpl

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
{%- if label is not none %}
2424
\label{{label}}
2525
{%- endif %} \\
26+
{% else %}
27+
{%- set label = parse_table(table_styles, 'label') %}
28+
{%- if label is not none %}
29+
\label{{label}} \\
30+
{% endif %}
2631
{% endif %}
2732
{% set toprule = parse_table(table_styles, 'toprule') %}
2833
{% if toprule is not none %}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ def test_position(styler):
109109
assert "\\end{table}" in styler.to_latex()
110110

111111

112-
def test_label(styler):
113-
assert "\\label{text}" in styler.to_latex(label="text")
112+
@pytest.mark.parametrize("env", [None, "longtable"])
113+
def test_label(styler, env):
114+
assert "\n\\label{text}" in styler.to_latex(label="text", environment=env)
114115
styler.set_table_styles([{"selector": "label", "props": ":{more §text}"}])
115-
assert "\\label{more :text}" in styler.to_latex()
116+
assert "\n\\label{more :text}" in styler.to_latex(environment=env)
116117

117118

118119
def test_position_float_raises(styler):

0 commit comments

Comments
 (0)