Skip to content

ENH: to_latex(): add posibility to define the latex environment (instead of table) #37443

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

Closed
horror-vacui opened this issue Oct 27, 2020 · 5 comments · Fixed by #41866
Closed
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Milestone

Comments

@horror-vacui
Copy link

Is your feature request related to a problem?

I wish pandas's to_latex() function could create table* environment instead of table for wide tables. The generated table sometimes does not fit into one column of a two column document.

Describe the solution you'd like

A parameter where one can define the name of the environment. E.g. df.to_latex(env="foobar*") to generate: \begin{foobar*} table stuff here \end{foobar*}.

API breaking implications

One more parameter.

Describe alternatives you've considered

Write a code, which replaces begin{table} and end{table} to the desired environment. (table* in most of the cases)

@horror-vacui horror-vacui added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 27, 2020
@bashtage
Copy link
Contributor

Why not just df.to_latex().replace("{table}","{table*}")? Since you aren't proposing fundamentally changing the rendering of the table, it seems like there is not a strong case for expanding the API.

@bashtage bashtage added the IO LaTeX to_latex label Oct 28, 2020
@horror-vacui
Copy link
Author

horror-vacui commented Oct 29, 2020

Why not just df.to_latex().replace("{table}","{table*}")? Since you aren't proposing fundamentally changing the rendering of the table, it seems like there is not a strong case for expanding the API.

I would be happy to use something like that, but the snippet you wrote, does not work with the latest release (1.1.3).

Traceback (most recent call last):
  File "soa.py", line 236, in <module>
    column_format="cccccccccccccc"
AttributeError: 'NoneType' object has no attribute 'replace'

for

df_table.to_latex(
            buf=tex_out,
            index=False,
            caption="Comparison with the State of the Art",
            label="tab:soa",
            na_rep="---",
            escape=False,
            bold_rows=True,
            column_format="cccccccccccccc"
            ).replace("{table}","{table*}")

@bashtage
Copy link
Contributor

You need to not pass buf to get a string, which you can then call replace on.

buf.write(
    df_table.to_latex(
        index=False,
        caption="Comparison with the State of the Art",
        label="tab:soa",
        na_rep="---",
        escape=False,
        bold_rows=True,
        column_format="cccccccccccccc",
    ).replace("{table}", "{table*}")
)

@bashtage bashtage added Closing Candidate May be closeable, needs more eyeballs and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 29, 2020
@attack68 attack68 added the Styler conditional formatting using DataFrame.style label May 9, 2021
@Kreijstal
Copy link

Kreijstal commented May 28, 2021

I would like to have this functionality, you don't necessarily need a tabular envirionment, it could be a matrix, a pmatrix, or some other environment. Or maybe you don't want any headers at all!

@Kreijstal
Copy link

@jreback there is still no option to allow no environment at all, there are only 2 environments allowed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants