3

I want to repeat the caption of a longtable on different pages.

  1. Is there any way (other than defining a new variable to save the caption) to get it.
  2. How can I get rid of the extra line after the caption for the first time, i.e., the header of the longtable in the first page.

MWC (you can replace images ):

\documentclass[preprint, 12pt]
\usepackage[table]{xcolor}   % colored rows
\usepackage{longtable}

\begin{document}
\begin{longtable}{|c|c|c|}
\caption{Step by step execution trace of Algorithm \ref{algo:CWM}}
\label{tab:example01Table}


% %\begin{tabular}{|c|c|c|}

%
\\       % <=====  I want to get rid of this line please 
\rowcolor{gray}
\# & Heap & Tour \\ 
\hline\hline
\endfirsthead
%
\multicolumn{3}{c}%
        {{(Cont.) Table \thetable: Step by step execution trace of Algorithm }} \\

\rowcolor{gray}
\# & Heap & Tour \\ 
\hline\hline
\endhead

%

0 &  Empty & \includegraphics[width=\mylength]{t00.pdf} \\\hline
1 & \includegraphics[width=\mylength]{h01.pdf} & \includegraphics[width=\mylength]{t01.pdf} \\ \hline
2 & \includegraphics[width=\mylength]{h02.pdf} & \includegraphics[width=\mylength]{t02.pdf} \\ \hline
3 & \includegraphics[width=\mylength]{h03.pdf} & \includegraphics[width=\mylength]{t03.pdf} \\ \hline
4 & \includegraphics[width=\mylength]{h04.pdf} & \includegraphics[width=\mylength]{t04.pdf} \\\hline
5 & \includegraphics[width=\mylength]{h05.pdf} & No Change \\ \hline
6 & \includegraphics[width=\mylength]{h06.pdf} & No Change \\ \hline
7 & \includegraphics[width=\mylength]{h07.pdf} & \includegraphics[width=\mylength]{t07.pdf} \\ \hline
8 & \includegraphics[width=\mylength]{h08.pdf} & No Change \\ \hline
9 & \includegraphics[width=\mylength]{h09.pdf} & \includegraphics[width=\mylength]{t09.pdf} \\\hline
10 & \includegraphics[width=\mylength]{h10.pdf} & \includegraphics[width=\mylength]{t10.pdf} \\ \hline
11 & \includegraphics[width=\mylength]{h11.pdf} & \includegraphics[width=\mylength]{t11.pdf} \\ \hline
- & - & \includegraphics[width=\mylength]{finalTour.pdf} \\ \hline

% %\end{tabular}

\end{longtable}
\end{document}
2
  • rather than say "MWC (you can replace images ):" it's more helpful to make the example not need them, use \rule or the demo option to graphicx Commented Feb 2, 2014 at 15:24
  • If I run your example I get ! TeX capacity exceeded, sorry [input stack size=5000]. \reserved@a ...int, 12pt}][{table}]\@clsextension Commented Feb 2, 2014 at 15:25

2 Answers 2

5

Please always post minimal WORKING examples.

  1. You can load the nameref package and then use it as in

    \multicolumn{3}{c}%
            {{(Cont.) Table \thetable: \nameref{tab:example01Table}}}
    
  2. You can load the caption package and issue the command:

    \captionsetup[longtable]{aboveskip=0pt}
    

MWE

\documentclass{article}
\usepackage[table]{xcolor}   % colored rows
\usepackage{longtable}
\usepackage[demo]{graphicx}

\usepackage{caption}
\captionsetup[longtable]{aboveskip=0pt}

\usepackage{nameref}

\begin{document}
\begin{longtable}{|c|c|c|}
\caption{Step by step execution trace of Algorithm \ref{algo:CWM}}
\label{tab:example01Table}


% %\begin{tabular}{|c|c|c|}

%
\\       % <=====  I want to get rid of this line please
\rowcolor{gray}
\# & Heap & Tour \\
\hline\hline
\endfirsthead
%
\multicolumn{3}{c}%
        {{(Cont.) Table \thetable: \nameref{tab:example01Table}}} \\

\rowcolor{gray}
\# & Heap & Tour \\
\hline\hline
\endhead

%

0 &  Empty & \includegraphics{t00.pdf} \\\hline
1 & \includegraphics{h01.pdf} & \includegraphics{t01.pdf} \\ \hline
2 & \includegraphics{h02.pdf} & \includegraphics{t02.pdf} \\ \hline
3 & \includegraphics{h03.pdf} & \includegraphics{t03.pdf} \\ \hline
4 & \includegraphics{h04.pdf} & \includegraphics{t04.pdf} \\\hline
5 & \includegraphics{h05.pdf} & No Change \\ \hline
6 & \includegraphics{h06.pdf} & No Change \\ \hline
7 & \includegraphics{h07.pdf} & \includegraphics{t07.pdf} \\ \hline
8 & \includegraphics{h08.pdf} & No Change \\ \hline
9 & \includegraphics{h09.pdf} & \includegraphics{t09.pdf} \\\hline
10 & \includegraphics{h10.pdf} & \includegraphics{t10.pdf} \\ \hline
11 & \includegraphics{h11.pdf} & \includegraphics{t11.pdf} \\ \hline
- & - & \includegraphics{finalTour.pdf} \\ \hline

% %\end{tabular}

\end{longtable}
\end{document} 

Output:

enter image description here

2
  • Thank you for your help. If I must set the vertical skip manually?
    – remo
    Commented Feb 3, 2014 at 8:41
  • @remo. For example, if you want 10pt as a vertical skip, use \captionsetup[longtable]{aboveskip=10pt} and \multicolumn{3}{c} {{(Cont.) Table \thetable: \nameref{tab:example01Table}}} \\[10pt] Commented Feb 3, 2014 at 8:47
7

Packages nameref or zreftitleref remember the caption titles:

\documentclass{article}
\usepackage{longtable}
\usepackage{caption}
\captionsetup[longtable]{aboveskip=0pt}

\usepackage{nameref}
\usepackage{zref-titleref, zref-user}

\begin{document}
  \begin{table}
    \centering
    \caption{Table caption}\label{tab}\zlabel{tab}
  \end{table}

  \begin{longtable}{lll}
    \caption{Longtable caption}\label{longtab}\zlabel{longtab}\\
    nameref:& \nameref{tab} & \nameref{longtab}\\
    ztitleref:& \ztitleref{tab} & \ztitleref{longtab}
  \end{longtable}
\end{document}

Result

Remark:

  • The space below the caption is removed by the help of package caption as shown in karlkoeller`s answer.
1
  • What about my second problem i.e., the extra space after the caption of the long table?
    – remo
    Commented Feb 3, 2014 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .