[Tex/LaTex] List of Figures – Continued

table of contents

I want to include "List of Figures – Continued" on the second page of the list of figures (LOF). Following this page, How to add some text to every page of the TOC?, I am using the \afterpage command. This works well except when there is only one figure on the second page. Then, the "List of Figures – Continued" is placed on the page after the second LOF page. Below is a minimal code that reproduces the error. When the number of figures is 46, everything works well. When the number of figures is 45, the "List of Figures – Continued" text is put on page 3 instead of page 2.

\documentclass{article}

\usepackage{graphicx}
\usepackage{afterpage}

% Command to add "List of figures - Continued"
\newcommand{\contheadingadv}[3][0]{%
  \afterpage{{\normalfont\centering\uppercase{#2~-~Continued}\\[1em]#3\hfill Page\\[1.5em]}}
}

\begin{document}

% Create list of figures
\listoffigures
\addtocontents{lof}{\contheadingadv[2]{List of figures}{Figure}}
\clearpage

% Loop to create figures
\newcount\loopcount
\loopcount 46   % Works with 46, doesn't work with 45 !!!!!!!!!!
\loop 
  \begin{figure}[h!]
    \centering
    \includegraphics[width=3cm]{example-image-a}
    \caption{Figure}
  \end{figure} 
  \clearpage
\advance\loopcount-1
\ifnum\loopcount>0
\repeat 

\end{document}

Best Answer

Such long list of figures are generally encountered in theses. The code snippet below is used by many universities around the globe in their .cls files. I hope this helps.

\def\listoffigures{
   \clearpage
   \typeout{LIST OF FIGURES.}
   \def\headmark{\vbox{
        \hbox to \textwidth{\large\bfseries\hfil LIST OF FIGURES
           (Continued) \hfil}
        \vspace{\innerheadskip}
        \hbox to \textwidth{\normalsize\bfseries
           \underbar{FIGURE}\hfil\underbar{PAGE}}}}
   \pagestyle{continued}
   \list@of@figs
   }