0

I'm using \documentclass[12pt,a4paper,twoside]{report} for making a report.

The entire report is divided into two parts. Each part contains chapters. The sample index is as follows.

List of Figures

List of Tables

Part I A

Chapter 1

1.1

Chapter 2

2.1

Part II B

Chapter 1

1.1

Chapter 2

2.1

In the list of figures and list of tables portions, I want to add only the part name in as shown below.

List of Figures

Part I A

1.1 Caption of Figure

2.1 Caption of Figure

Part II B

1.1 Caption of Figure

2.1 Caption of Figure

Please give me necessary solutions to do it.

CarLaTeX
  • 62,716

2 Answers2

2

A patch answer by changing \@part a little bit and explicitly adding \addcontentsline with lof instead of toc again.

I have kept the vertical chapter gap in the LoF in order make the elements of figures origination from different chapters more outstanding.

\documentclass{report}

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@part}{%
  \markboth{}{}% Find a hook in order to append content. 
}{%
  \markboth{}{}%
  \ifnum\c@secnumdepth>-2\relax
  \addcontentsline{lof}{part}{\thepart\hspace{1em}#1}%
  \else
  \addcontentsline{lof}{part}{#1}%
  \fi
}{\typeout{Success}}{\typeout{Patch failure}}
\makeatother

\usepackage{hyperref}

\begin{document}
\tableofcontents
\listoffigures

\part{Number Three -- the Larch}



\chapter{A dummy chapter}
\begin{figure}

\caption{First figure}

\end{figure}


\begin{figure}

\caption{Second figure}

\end{figure}

\part{And now for something completely different}

\begin{figure}

\caption{Third figure}

\end{figure}


\end{document}

enter image description here

1

I adjusted this answer to include the parts and not the chapters in the list of figures:

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{etoolbox}

\makeatletter
\def\thisparttitle{}
\def\thispartnumber{}
\newtoggle{noFigs}
\apptocmd{\@part}{\gdef\thisparttitle{#1}\gdef\thispartnumber{\thepart}\global\toggletrue{noFigs}}{}{}
\AtBeginDocument{\AtBeginEnvironment{figure}{%
  \iftoggle{noFigs}{
    \addtocontents{lof}{\protect\contentsline{part}{\protect\numberline{\thispartnumber}{\thisparttitle}}{}{}}
    \global\togglefalse{noFigs}
  }{}
}}
\makeatother

\begin{document}

\listoffigures

\part{A}
\chapter{First}
\begin{figure}[h]
    \caption{Caption of first figure}
\end{figure}
\chapter{Second}
\begin{figure}[h]
    \caption{Caption of second figure}
\end{figure}

\part{B}
\chapter{First}
\begin{figure}[h]
    \caption{Caption of third figure}
\end{figure}
\chapter{Second}
\begin{figure}[h]
    \caption{Caption of fourth figure}
\end{figure}

\end{document}

enter image description here

Tiuri
  • 7,749