ENH: Correct use of `longtable`, `label`, and `caption` with LaTeX
See original GitHub issueIs your feature request related to a problem?
Currently DataFrame.to_latex()
has a longtable
argument, which writes the DataFrame to latex using the syntax of the longtable package. When used with the label
and caption
arguments, it writes a latex table with all of these features.
However, the caption and label are both placed between a \begin{longtable}
line and \endhead
. As a consequence, the table appears twice in the listoftables
and leads to warnings about the reference being multiply defined
Describe the solution you’d like
the .to_latex()
method when longtable=True
and caption=X
and label=Y
should print out as follows
\begin{longtable}{...}% alignment characters
\caption{Caption here}\label{label-here}
\endfirsthead
\caption{Caption here}
\endhead
This will prevent a separate label from being defined multiple times in latex (once for each page the caption is printed on). See page 5 of http://www.texdoc.net/texmf-dist/doc/latex/tools/longtable.pdf.
API breaking implications
None
Describe alternatives you’ve considered
An alternative is to set the caption and label to False, and to add them myself. This works but defeats the purpose of calling the .to_latex()
API
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
@jdossgollin thanks for identifying this. I didn’t give the repeated entries in the List of Tables much thought initially because the table is indeed occupying multiple pages. I can take this and revise such that the List of Tables looks cleaner. Thanks for doing all the hard work!
thanks for taking this on!