Skip to content

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

Open
@Sleepingwell

Description

@Sleepingwell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIO LaTeXto_latexStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions