In a table of contents style list of figures I would like to combine the appearance of each of these questions.
Part title in list of figures and tables?
Include chapters in List of Figures with titletoc?
Part title
Chapter title
List of Figures in this chapter
Chapter title
List of Figures in this chapter
Part title
Chapter title
List of Figures in this chapter
Chapter title
List of Figures in this chapter
I have tried to combine the parts, but in my MWE below, I don't seem to get the inclusion of the parts titles and I can't seem to change the formatting of these newly added titles. I need to add a little more space between them and make them more visibly different from the titles of the figures I am referencing?
\documentclass{report}
\usepackage{etoolbox} % or xpatch
\usepackage{bookmark}
\usepackage{hyperref}
\makeatletter
% initial definitions of the part info (name and number)
\def\thisparttitle{}\def\thispartnumber{}
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newtoggle{noTabs}
\apptocmd{\@chapter}{\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}\global\toggletrue{noFigs}}{}{}
\apptocmd{\@part}{\gdef\thisparttitle{#1}\gdef\thispartnumber{\thepart}\global\toggletrue{noFigs}\global\toggletrue{noTabs}}{}{}
% the figure environment does the job: the first time it is used after a \chapter command, it writes the information of the chapter to the LoF
\AtBeginDocument{%
\AtBeginEnvironment{figure}{%
\iftoggle{noFigs}{
\addtocontents{lof}{\protect\contentsline{part}%
{\protect\numberline{\thisparttitle}}{}{3.2em} }
\addtocontents{lof}{\protect\contentsline {chapter}%
{\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
\global\togglefalse{noFigs}
}{}
}%
\AtBeginEnvironment{table}{%
\iftoggle{noTabs}{
\addtocontents{lot}{\protect\contentsline{part}%
{\protect\numberline{\thisparttitle}}{}{} }
\addtocontents{lot}{\protect\contentsline {chapter}%
{\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
\global\togglefalse{noTabs}
}{}
}%
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\part{The first}
\chapter{Introduction with no Figures}
\chapter{Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter{Test Chapter with no Figures}
\part{The second}
\chapter{Another Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\end{document}
UPDATE
If I replace the document block of the solution below with this:
\begin{document}
\tableofcontents
\listoffigures
\part{The first}
\chapter{Introduction with no Figures}
\chapter{Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter{Test Chapter with no Figures}
\part{The second}
\chapter{Look no figures here either}
\chapter{Another Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter{Another in the same part}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\end{document}
I then get:
which duplicates Part titles even when the chapters are sequential (4 and 5 circled in blue to highlight this) and aren't interspersed with a chapter missing figures.
Best Answer
The
\contentsline
stuff is wrongly used in the O.P.'s document, i.e. wrongly placed{}
delimiters.For example
tries to write a
\numberline
with the part title as the number, leaving out the title and setting the page number to be3.2em
which is in fact a length.One correct way is
The same holds true for the chapter titles and the
LoT
.Edit
Now with
hyperref
support, but without showing the page number for chapters and parts. (Please note: due to the toggle style, this won't work if a figure is not in a chapter!) The better way would to ask for the figure number.