# Part title in list of figures and tables?

I'm using KOMAScript. I have a \listoffigures and a \listoftables. My document has several \part{}'s. In the two lists the figures and tables are already grouped (small vertical space) by the chapters.

What I'd like to have additionally to the ("anonymous") chapter vspace grouping is the part title over each "part group" of figures and tables in the two lists. Is this somehow possible without having to code a list from scratch?

-
Does every part contain tables and figures? If not the code has to be more complex. –  egreg Mar 23 '13 at 15:54
No. It's possible that a part does only have figures or tables or none of them or both. –  Foo Bar Mar 23 '13 at 15:56
I just made an edit: the vspace grouping happens on every chapter, of course (not part). But I'd like to have the part title in the lists. –  Foo Bar Mar 23 '13 at 15:59

You can setup your own entry by:

\newcommand{\addtocentrylistof}[3]{%
\ifstr{#2}{}{%
}{%
}%
}

}


Here a small example:

\documentclass[english]{scrreprt}
\usepackage{babel}
\ifstr{#2}{}{%
}{%
}%
}

}
\def\examplefig{\begin{figure}[!ht]\caption{foo}\end{figure}\begin{table}[!ht]\caption{foo}\end{table}}
\begin{document}
\tableofcontents
\listoffigures
\listoftables

\part{O I}
\chapter{foo}
\examplefig\examplefig\examplefig
\chapter{foo}
\examplefig\examplefig\examplefig
\chapter{foo}
\examplefig\examplefig\examplefig
\part{O II}
\chapter{bar}
\examplefig\examplefig\examplefig
\chapter{bar}
\examplefig\examplefig\examplefig
\chapter{bar}
\examplefig\examplefig\examplefig

\end{document}

-
This works perfectly and is easier, so I chose this one. Thanks. :) –  Foo Bar Apr 14 '13 at 17:14

This is just an adaptation from this answer to Include chapters in List of Figures with titletoc? . The inclusion is made automatically using the standard commands and only for the parts with figures:

\documentclass{scrreprt}
\usepackage{etoolbox} % or xpatch

\makeatletter
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newtoggle{noTabs}

\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}{
{\protect\numberline {\thispartnumber} {\thisparttitle}}{}{} }
\global\togglefalse{noFigs}
}{}
}%
\AtBeginEnvironment{table}{%
\iftoggle{noTabs}{
{\protect\numberline {\thispartnumber} {\thisparttitle}}{}{} }
\global\togglefalse{noTabs}
}{}
}%
}

\makeatother

\begin{document}

\tableofcontents
\listoffigures
\listoftables

\part{Test Part With Figures and Tables}
\chapter{Test Chapter with Figures and Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}

\part{Test Part with no Figures and no Tables}

\part{Test Part with no Figures and Tables}
\chapter{Test Chapter with Table}
\begin{table}
\caption{caption text for a table}
\end{table}

\part{Test Part with no Tables and Figures}
\chapter{Test Chapter with Figure}
\begin{figure}
\caption{caption text}
\end{figure}

\part{Another Test Part With Figures and Tables}
\chapter{Another Test Chapter}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}

\end{document}


An image of the LoF:

An image of the LoT:

-
@Speravir xpatch loads etoolbox –  egreg Mar 23 '13 at 16:08
@egreg Aaah, forgot this. Thanks, and sorry to Gonzalo! –  Speravir Mar 23 '13 at 16:09
Thanks, but I get the error Use of \H@old@part doesn't match its definition. at each occurence of \part. –  Foo Bar Mar 23 '13 at 16:16
@Speravir No problem ;-) –  Gonzalo Medina Mar 23 '13 at 16:16
@FooBar Do you get the error with my exact code? If not, please add the code you use as an edit to your question. –  Gonzalo Medina Mar 23 '13 at 16:17