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: Correct use of `longtable`, `label`, and `caption` with LaTeX

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jeschwarcommented, Sep 4, 2020

@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!

0reactions
jdossgollincommented, Sep 4, 2020

thanks for taking this on!

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to have a caption on top of longtable? - TeX
To start with, remove the \begin{center} and \end{center} instructions -- a longtable is automatically centered. Second, add a double backslash ...
Read more >
Customizing captions of floating environments - TeXDoc
Abstract. The caption package offers customization of captions in floating environments such figure and table and cooperates with many other ...
Read more >
The bicaption package - CTAN
The \label should be placed either after this command, or inside the first heading. Bilingual caption boxes will be typeset by. \bicaptionbox. \ ......
Read more >
The floatrow package - CTAN
At the final variant of document you may need to correct vertical spaces between float and main text, between float object and caption....
Read more >
The longtable package
Thus the caption for table 1 was specified as \caption[An optional table caption. (used in the list of tables)]{A long table\label{long}}. You ...
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