Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

2 Answers

up vote 4 down vote accepted

You can setup your own entry by:

\newcommand{\addtocentrylistof}[3]{%
  \ifstr{#2}{}{%
    \addcontentsline{lof}{#1}{#3}%
    \addcontentsline{lot}{#1}{#3}%
  }{%
    \addcontentsline{lof}{#1}{\protect\numberline{#2}#3}%
    \addcontentsline{lot}{#1}{\protect\numberline{#2}#3}%
  }%
}

\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{#1}{#2}%
  \addtocentrylistof{part}{#1}{#2}%
}

Here a small example:

\documentclass[english]{scrreprt}
\usepackage{babel}
\newcommand{\addtocentrylistof}[3]{%
  \ifstr{#2}{}{%
    \addcontentsline{lof}{#1}{#3}%
    \addcontentsline{lot}{#1}{#3}%
  }{%
    \addcontentsline{lof}{#1}{\protect\numberline{#2}#3}%
    \addcontentsline{lot}{#1}{\protect\numberline{#2}#3}%
  }%
}

\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{#1}{#2}%
  \addtocentrylistof{part}{#1}{#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}
share|improve this answer
    
This works perfectly and is easier, so I chose this one. Thanks. :) –  Foo Bar Apr 14 '13 at 17:14
add comment

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}{
      \addtocontents{lof}{\protect\contentsline {part}%
        {\protect\numberline {\thispartnumber} {\thisparttitle}}{}{} }
      \global\togglefalse{noFigs}
    }{}
  }%
  \AtBeginEnvironment{table}{%
    \iftoggle{noTabs}{
      \addtocontents{lot}{\protect\contentsline {part}%
        {\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:

enter image description here

An image of the LoT:

enter image description here

share|improve this answer
    
@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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.