Open Sleepingwell opened 2 years ago
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 is the api suggested by @Sleepingwell approved? If so I would add a PR (for the Styler
only).
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.
So should the we call the param caption_position_top
then?
Otherwise it's kind of murky: caption_position=True
and caption_position=False
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
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.
caption_top : True or False is probably best
On Mon, 5 Dec 2022 at 11:39, DanielHabenicht @.***> wrote:
So should the we call the param caption_position_top then?
Otherwise it's kind of murky: caption_position=True and caption_position=False
— Reply to this email directly, view it on GitHub https://github.com/pandas-dev/pandas/issues/46122#issuecomment-1337112966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZCAKTN4MNLUNJRFEQVBCLWLXA7ZANCNFSM5PC5HPWQ . You are receiving this because you were mentioned.Message ID: @.***>
This would be something really useful
zZZzzZZ
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
andFalse
.I think the docstring would be something like
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 ofDataFrame.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.