-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Correct use of longtable
, label
, and caption
with LaTeX
#34360
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
longtable
, ` with LaTeXlongtable
, label
, and caption
with LaTeX
cc @SylvainLan and @jeschwar if either of you have thoughts. @jdossgollin it'd be helpful if you provide a minimal example constructing a small DataFrame and showing the output http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-report. |
Sure thing. import pandas as pd
df = pd.DataFrame({"a": range(5), "b": range(5)})
print(df.to_latex(longtable=True, caption="longtable data frame", label="tab:demo")) gives \begin{longtable}{lrr}
\caption{longtable data frame}\label{tab:demo}\\
\toprule
{} & a & b \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\endlastfoot
0 & 0 & 0 \\
1 & 1 & 1 \\
2 & 2 & 2 \\
3 & 3 & 3 \\
4 & 4 & 4 \\
\end{longtable} I would like instead for the table to show \begin{longtable}{lrr}
\caption{longtable data frame}\label{tab:demo}\\
\toprule
{} & a & b \\
\midrule
\endfirsthead
% now repeat everything from above, but add a [] to the caption and don't print the label
\caption[]{Desired behavior with a very long longtable}\\ % the [] here keeps it from showing up again in \listoftables
\toprule % identical
{} & a & b \\ % identical
\midrule % identical
\endhead
... Here's a live example of how the difference plays out in a document: https://www.overleaf.com/read/wyypsqptyqvb |
@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! |
take |
thanks for taking this on! |
Test for longtable with shorcaption was changed to reflect the recent changes on master branch. The changes in longtable environment were introduced recently, see GH pandas-dev#34360.
Is your feature request related to a problem?
Currently
DataFrame.to_latex()
has alongtable
argument, which writes the DataFrame to latex using the syntax of the longtable package. When used with thelabel
andcaption
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 thelistoftables
and leads to warnings about the reference being multiply definedDescribe the solution you'd like
the
.to_latex()
method whenlongtable=True
andcaption=X
andlabel=Y
should print out as followsThis 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()
APIThe text was updated successfully, but these errors were encountered: