Skip to content

ENH: Add option for bold_column_headers to to_latex() #46790

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

Open
mosc9575 opened this issue Apr 16, 2022 · 3 comments
Open

ENH: Add option for bold_column_headers to to_latex() #46790

mosc9575 opened this issue Apr 16, 2022 · 3 comments

Comments

@mosc9575
Copy link
Contributor

In the latest pandas version 1.4.2 there exists an option to enable bold rows but there isn't a similar option to do the same for the columns. It is something some users on SO were asking for and it seems very logical.

The example from the official documentation with bold_rows=True and bold_column_headers=True should lead to the following example.

import pandas as pd

df = pd.DataFrame(
    dict(name=['Raphael', 'Donatello'],
         mask=['red', 'purple'],
         weapon=['sai', 'bo staff']
        )
)
result= df.to_latex(bold_rows=True, bold_column_headers=True)

>>> result
\begin{tabular}{llll}
\toprule
{} &       \textbf{name} &    \textbf{mask} &    \textbf{weapon} \\
\midrule
\textbf{0} &    Raphael &     red &       sai \\
\textbf{1} &  Donatello &  purple &  bo staff \\
\bottomrule
\end{tabular}
@mosc9575 mosc9575 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 16, 2022
@attack68
Copy link
Contributor

this is currently possibly with Styler.

df.style.applymap_index(lambda v: "font-weight: bold;", axis="columns").to_latex(convert_css=True)

or

df.style.applymap_index(lambda v: "textbf:--rwrap;", axis="columns").to_latex()

or

df.style.applymap_index(lambda v: "bfseries:;", axis="columns").to_latex()

The medium term objective is for the Styler implementation, which is much more flexible, will replace the DataFrame LaTeX formatter.

@attack68 attack68 added IO LaTeX to_latex and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 17, 2022
@jreback
Copy link
Contributor

jreback commented Apr 17, 2022

@attack68 maybe worth adding this to the docs somewhere and closing this

@attack68
Copy link
Contributor

@jreback I have docs and and WIP PR for DataFrame.to_latex ready for this but it relies on #45288, which is in-limbo. Would appreciate your second look that one, and either we close or find some agreement forward, then I can resolve other PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants