question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Styler.to_latex()

See original GitHub issue

I have created a branch adding a to_latex method to Styler.

It is nowhere near readiness, and in particular:

  • supports only cell background color as of now - adding some attributes should be trivial, adding others might be less so
  • most importantly, it works on a copy of the dataframe casted .astype(str), which is plain wrong because it discards features such as float formatting. For a good result, a better integration is needed with the code that currently does cell formatting in DataFrame.to_latex.

This said, if anyone feels like experimenting, it might be slightly better than starting from scratch.

One aspect which I think is useful, even aside from this branch, and might benefit some discussion, is the pair of methods _latex_preserve and _latex_restore, which basically replace LaTeX commands so that they are not disturbed by escaping, and then restores them. There might be better way to code this, but I really think this is something we need to implement, and to offer to users who happen to nest LaTeX code in their cells.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:24
  • Comments:67 (49 by maintainers)

github_iconTop GitHub Comments

3reactions
MarcoGorellicommented, Jan 3, 2021

Please, this isn’t helpful - see here for how to contribute, else wait for someone else to do it, but carrying on commenting +1 is disruptive

1reaction
moi90commented, Dec 10, 2021

include \midrule after a specific row

For that, I usually split the generated output into individual lines, insert the extra rules at pre-defined locations and concatenate the result. This breaks easily but it is better than nothing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.io.formats.style.Styler.to_latex
Write Styler to a file, buffer or string in LaTeX format. New in version 1.3.0. ... Defaults to 'l' for index and non-numeric...
Read more >
pandas style options to latex - python - Stack Overflow
Pandas has two nice functionalities I use a lot - that's the df.style... option and the df.to_latex() call. But I do not know...
Read more >
huxtable.pdf
Simple, modern interface to manipulate borders, size, position, captions, colours, text styles and number formatting. Table cells can span multiple rows and/or ...
Read more >
Introduction-to-Pandas--slides.pdf - Forschungszentrum Jülich
Let's add names to ages; put everything into a dict(). In [14]: data = { ... It is recommended instead to use `DataFrame.style.to_latex....
Read more >
Changelog • huxtable
A new brdr() class encapsulates border thickness, style and colour. ... Enhancement: when stars is NULL in huxreg , don't print a note...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found