-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: .to_latex(longtable=True) latex caption and label support #25339
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
ENH: .to_latex(longtable=True) latex caption and label support #25339
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25339 +/- ##
==========================================
- Coverage 91.72% 91.71% -0.01%
==========================================
Files 173 173
Lines 52831 52842 +11
==========================================
+ Hits 48457 48462 +5
- Misses 4374 4380 +6
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #25339 +/- ##
==========================================
- Coverage 91.72% 91.71% -0.01%
==========================================
Files 173 173
Lines 52831 52842 +11
==========================================
+ Hits 48457 48462 +5
- Misses 4374 4380 +6
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is label / caption useful to a tabular write?
you would need to add a test for this
@jreback that is a good suggestion to allow the
|
@jeschwar not a LaTeX expert by any means but your proposal makes sense. Can you open as an issue and reference that from this PR? That is typically easiest for change management |
git diff upstream/master -u -- "*.py" | flake8 --diff
When creating a latex table with
DataFrame.to_latex(longtable=False)
the output is written inside a latextabular
environment and stored in some file likepandas_tabular.tex
; the user can conveniently typeset the table in a mainreport.tex
file complete with caption and label as follows:This is good because the
pandas_tabular.tex
file can be re-created and the mainreport.tex
simply needs to be recompiled to get the updated output.The problem when creating a latex longtable with
DataFrame.to_latex(longtable=True)
is the caption and label need to go inside the latexlongtable
environment which is stored in a some file likepandas_longtable.tex
. The latexlongtable
environment does not go inside atable
environment like thetabular
environment does; this means that setting the caption and label requires the user to edit thepandas_longtable.tex
file after its creation. This does not support an automated workflow like we have with thetabular
environment.This PR adds caption and label support to
DataFrame.to_latex(longtable=True)
with the argumentslt_caption
andlt_label
. Example usage is described below.The following python code creates some data in a
DataFrame
and writes it to disk intabular
andlongtable
latex environments:The following latex code is contained in a main
report.tex
and is used to typset both tables:Using
DataFrame.to_latex(longtable=True)
with the new argumentslt_caption
andlt_label
means we don't have to editpandas_longtable.tex
after its creation to get the caption and label working. This functionality also works withSeries.to_latex(longtable=True)
.PDF output is shown below: