Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add option to specify table captions to be below tables in DataFrame.to_latex #46122

Open
Sleepingwell opened this issue Feb 23, 2022 · 8 comments
Labels
Enhancement IO LaTeX to_latex Styler conditional formatting using DataFrame.style

Comments

@Sleepingwell
Copy link

Is your feature request related to a problem?

At present, table captions are always written above the table in the outputs. LaTeX will then render the caption above the table in the resulting document.

I prefer to put captions below tables (and figures) and would like the option to do so added to DataFrame.to_latex.

Describe the solution you'd like

I propose adding a new argument to DataFrame.to_latex, (say caption_position) with a default of 'above'and valid values of 'above' and 'below'. One could equivalently use an Enum, but I'm not sure where that would live and don't think this idiomatic w.r.t. Pandas.

An alternative would be an argument caption_above with valid values of True and False.

I think the docstring would be something like

"""
Parameters
----------
caption_position : str, default 'above'
    Position of the caption relative to the table. Acceptable values are `'above'` and `'below'`.
"""

API breaking implications

With a default, this should not change the API.

Describe alternatives you've considered

At present, I wait until I finally want to submit the document then manually change the files (where I put the output of DataFrame.to_latex) manually. Without this feature, I would consider writing a function that takes the output of DataFrame.to_latex and rearranges it.

Note

I'm happy to have a go at this — if it is not so trivial that someone can do it faster than saying OK — if people are happy with the proposed approach.

@Sleepingwell Sleepingwell added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2022
@attack68
Copy link
Contributor

Styler.to_latex can already completely replicate everything that DataFrame.to_latex does and has a lot more functionality. The intention is redirect DataFrame.to_latex to use the Styler implementation. If you submit a PR pls do so for the Styler implementation

@attack68 attack68 added IO LaTeX to_latex Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2022
@DanielHabenicht
Copy link

DanielHabenicht commented Dec 5, 2022

@attack68 is the api suggested by @Sleepingwell approved? If so I would add a PR (for the Styler only).

@attack68
Copy link
Contributor

attack68 commented Dec 5, 2022

Yes caption_position can be added. It is something that is generally quite useful.
The addition to Styler will not be as simple as it seems. It will require changing the jinja2 template and constructing tests for different environments including standard and longtable for example.

True and False are better since this is a binary decision.

@DanielHabenicht
Copy link

So should the we call the param caption_position_top then?

Otherwise it's kind of murky: caption_position=True and caption_position=False

@DanielHabenicht
Copy link

Yes caption_position can be added. It is something that is generally quite useful. The addition to Styler will not be as simple as it seems. It will require changing the jinja2 template and constructing tests for different environments including standard and longtable for example.

You certainly mean: https://github.com/pandas-dev/pandas/blob/v1.5.2/pandas/io/formats/templates/latex.tpl

Is this the old implementation then?:

https://github.com/pandas-dev/pandas/blob/v1.5.2/pandas/io/formats/latex.py#L610

@attack68
Copy link
Contributor

attack68 commented Dec 5, 2022

The second link is the old implementation. I have not contriubuted anything to that, so dont know my way around it. Focus on

style.py, styler_render.py, and the appropriate jinja2 templates.

@attack68
Copy link
Contributor

attack68 commented Dec 5, 2022 via email

@netphantom
Copy link

This would be something really useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

4 participants