# Divided list of figures

I am using this solution to divide my list of figures and tables into chapters, however, I have a section heading on its own at the bottom of a page and then the table captions are on the next page. What I want to do is force a new page when this happens (i.e when less than 2 figures are in the list say). The original thread is here - https://tex.stackexchange.com/a/68340/51337

I am sure the same could be down with the Table of contents to ensure that it doesn't look strange either, but I've no idea how. I know you can force a new page in the table of contents by adding \addtocontents{toc}{\protect\newpage} before the \chapter{} command, but this isn't really what I am after

    \documentclass{book}
\usepackage{etoolbox}

\makeatletter
\def\thischaptertitle{}
\apptocmd{\@chapter}{\gdef\thischaptertitle{#1}}{}{}

\newcommand{\DeclareDividedList}[1]%
{\newcounter{#1@chapter}\setcounter{#1@chapter}{0}}

{\ifltxcounter{#1@chapter}%
{%
\ifnumgreater{\thechapter}{\value{#1@chapter}}{%
\setcounter{#1@chapter}{\thechapter}%
{\protect\numberline {\thechapter} {\thischaptertitle}}{}{} }
}{}%
}{}%
}{}{}
\makeatother

\DeclareDividedList{lof}
\DeclareDividedList{lot}

\begin{document}

\tableofcontents
\listoffigures
\listoftables

\mainmatter

\chapter{Introduction with no Figures}

\chapter{Test Chapter with Figures but no Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}

\chapter{Test Chapter with Tables but no Figures}
\begin{table}
\caption{caption text}
\end{table}
\begin{table}
\caption{caption text}
\end{table}

\chapter{Test Chapter with Figures and Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}

\end{document}


I would make use of the needspace package and insert a \Needspace{<len>} just before the chapter heading:

\usepackage{needspace}% http://ctan.org/pkg/needspace
%...
{\ifltxcounter{#1@chapter}%
{%
\ifnumgreater{\value{chapter}}{\value{#1@chapter}}{%
\setcounter{#1@chapter}{\value{chapter}}%
\protect\contentsline{chapter}%
{\protect\numberline {\thechapter} {\thischaptertitle}}{}{} }
}{}%
}{}%
}{}{}
%...


Above I've used 3.5\baselineskip, but you may want to fiddle with this to be sure it accommodates your minimum 2-float requirement. The .lof for your minimal example now resembles:

\addvspace {10\p@ }
\Needspace {3.5\baselineskip }\contentsline {chapter}{\numberline {2} {Test Chapter with Figures but no Tables}}{}{}
\contentsline {figure}{\numberline {2.1}{\ignorespaces caption text}}{3}
\contentsline {figure}{\numberline {2.2}{\ignorespaces caption text}}{4}
\Needspace {3.5\baselineskip }\contentsline {chapter}{\numberline {4} {Test Chapter with Figures and Tables}}{}{}
\contentsline {figure}{\numberline {4.1}{\ignorespaces caption text}}{7}
\contentsline {figure}{\numberline {4.2}{\ignorespaces caption text}}{8}
\contentsline {figure}{\numberline {4.3}{\ignorespaces caption text}}{8}


What this means is a page break will be forced if there is less than 3.5\baselineskip available on the page at the time of setting the chapter heading.

It may not be an optimal solution, as a chapter with only a single figure might still fit at the bottom of the LoF/LoT, but it may also be sufficient.

To truly accommodate your request, one would have to keep track of the number of floats per chapter, and then condition on that when setting the chapter heading while keeping track of the location on the page at the same time.

• Does this need to go into side a \makeatletter and \makeatother? – Magiclamarshmallow Jun 27 '14 at 8:03