-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
[FR] add option to format \hline in to_latex() #28291
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
Comments
As a temporal solution, you can use "replace" function for strings in Python, to change those " \\ " at the end of your table rows by "\\ \hline" to have the horizontal lines. You need before to save your lateX code in a variable as below :
and then you perform the replace :
Best. |
@MoMoussabbih how does the merge help with this? i cant seem to undestand how to do it today without the replace you recommend. |
@jreback how can we use the code from that pr to solve this issue? I don't see it either. |
@attack68 maybe you can shed light on how one can add I guess it could be done by using something along the lines of (Not working!): .set_table_styles([
{'selector': 'toprule', 'props': ':toprule;'},
{'selector': 'bottomrule', 'props': ':hline;'},
{'selector': 'td', 'props': ':hline;'},
], overwrite=False) But I can't seem to get the right selector. Or is it simply not possible? (how is it done for vertical lines? should I create an extra issue?) |
No that doesnt work. The selctors are very specific, as documented. You cannot add HTML selectors and expect it to work - its not coded. (also td is a cell not a row, tr is a row and that wouldnt work either) If This will a bit chaotic with adding styles and css conversion though. |
Thanks, I think I got it now. For a fully lined table one would execute: df = pd.DataFrame([["a"], ["b"]])
print(df.style.set_table_styles([
{'selector': 'toprule', 'props': ':hline;'},
{'selector': 'midrule', 'props': ':hline;'},
{'selector': 'bottomrule', 'props': ':hline;'},
], overwrite=False).to_latex(clines="all;data", column_format="|l|l|")) Resulting in:
|
Please considering add a parameter to allow users to add
\hline
to the latex output so that each two rows will have a horizontal line between them.For example:
It will give me:
I wish the output could be
The text was updated successfully, but these errors were encountered: