3

I would like to know how to show Appendices' name in LOF if they contain figures.

    % % % % % % % % % % PACKAGES % % % % % % % % % % % % % 
    \documentclass[11pt,a4paper]{report}

    \usepackage[english]{babel}     % english language
    \usepackage{graphicx}           % images in the document
    \usepackage{float}              % containers
    \usepackage{wrapfig}            % wrap text around figure
    \usepackage{subfig}             % some images in a environment

    \usepackage{appendix}
    \usepackage{titlesec}
    \usepackage{chngcntr}

    % code to put chapter name in LOF (hyperref must be loaded after it)
    \usepackage{etoolbox}
    \makeatletter
    % initial definitions of the chapter info (name and number)
    \def\thischaptertitle{}\def\thischapternumber{}
    \newtoggle{noFigs}

    \apptocmd{\@chapter}%
      {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
        \global\toggletrue{noFigs}}{}{}

    % 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 {chapter}%
            {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
          \global\togglefalse{noFigs}
        }{}
      }%
    }

    % hyperlinks typesettings
    \usepackage[
        % comment this out to avoid backref in bibliography
        %backref=true,    % allows to add links inside...
        %pagebackref=true,% ...the bibliography
        hyperindex=true, % add links in the index
        bookmarks=true,  % show bookmarks bar when displaying the document}                {hyperref}
    ]{hyperref}
    \hypersetup{
    colorlinks=true, % colored links
    breaklinks=true, % allows return line in too long links
    urlcolor= blue,  % links color
    linkcolor= blue, % internal links color
    citecolor= blue, % green by defaut, color of citation links (bibliography)
    bookmarksopen=true,
    }

    % code to make appendices' sections look like chapters and subsections like sections in the body of the document
    \makeatletter
    \newcommand\changesections{%
    \renewcommand\thesection{\Alph{section}}
    \counterwithin{figure}{section}
    \counterwithin{table}{section}
    \renewcommand\thefigure{\thesection.\arabic{figure}}
    \titleclass{\section}{top}
    \newcommand\sectionbreak{\cleardoublepage}
    \titleformat{\section}[display]
    {\normalfont\huge\bfseries}{\chaptertitlename\ \thesection}{20pt}{\Huge}
    \titlespacing*{\section}
      {0pt}{50pt}{40pt}
    \titleformat{\subsection}
      {\normalfont\Large\bfseries}{\thesubsection}{1em}{}
    \titlespacing*{\subsection}
      {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
    }
    \makeatother


    % % % % % % % % % % RAPPORT % % % % % % % % % % % % % 
    \begin{document}

    \listoffigures
    \newpage

    % chapter 1:
    \chapter{Introduction}
    \section{Problem overview}
    \begin{figure}[H]
        \caption{Comparative table 1}
    \end{figure}

    \section{Application description}
    \begin{figure}[H]
        \caption{Comparative table 2}
    \end{figure}
    \newpage
    % end chapter 1 

    % appendices
    \appendix
    \clearpage % or \cleardoublepage
    \appendixpage
    \addappheadtotoc
    % code to show appendices at section level in TOC
    \begin{appendices}
    \changesections
    \section{Installation requirements}    
    \section{Performance evaluation I appendix}     
    \subsection{Strahov}
    \begin{figure}[H]
        \caption{Comparative table 3}
    \end{figure}

    \subsection{University laboratory}
    \begin{figure}[H]
        \caption{Comparative table 4}
    \end{figure}

    \end{appendices}
    % end appendices

    \end{document}

Now, LOF is displayed like this:

LOF

Notice the piece of code to show Chapters' name in LOF if they contain figures, and the piece of code to make appendices' sections look like chapters and subsections like sections in the body of the document.

1 Answer 1

1

A little modification has to be done; I used a boolean switch appendices initially set to false; if the switch is false, then the information of the chapters is added to the LoF; if the switch is true, the information of the modified section is included in the LoF; to have easy access to the titles, I also used the explicit option for titlesec:

\documentclass[11pt,a4paper]{report}
\usepackage[english]{babel}     % english language
\usepackage{graphicx}           % images in the document
\usepackage{float}              % containers
\usepackage{wrapfig}            % wrap text around figure
\usepackage{subfig}             % some images in a environment

\usepackage{appendix}
\usepackage[explicit]{titlesec}
\usepackage{chngcntr}

% code to put chapter name in LOF (hyperref must be loaded after it)
\usepackage{etoolbox}
\makeatletter
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newbool{appendices}
\setbool{appendices}{false}
\apptocmd{\@chapter}%
  {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
    \global\toggletrue{noFigs}}{}{}

% 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}{
      \ifbool{appendices}
       {\addtocontents{lof}{\protect\contentsline {chapter}%
         {\protect\numberline {\thissectionnumber} {\thissectiontitle}}{}{} }}
       {\addtocontents{lof}{\protect\contentsline {chapter}%
          {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }}
      \global\togglefalse{noFigs}
    }{}
  }%
}

% hyperlinks typesettings
\usepackage[
    % comment this out to avoid backref in bibliography
    %backref=true,    % allows to add links inside...
    %pagebackref=true,% ...the bibliography
    hyperindex=true, % add links in the index
    bookmarks=true,  % show bookmarks bar when displaying the document}                {hyperref}
]{hyperref}
\hypersetup{
colorlinks=true, % colored links
breaklinks=true, % allows return line in too long links
urlcolor= blue,  % links color
linkcolor= blue, % internal links color
citecolor= blue, % green by defaut, color of citation links (bibliography)
bookmarksopen=true,
}

% code to make appendices' sections look like chapters and subsections like sections in the body of the document
\makeatletter
\newcommand\changesections{%
\setbool{appendices}{true}
\renewcommand\thesection{\Alph{section}}
\counterwithin{figure}{section}
\counterwithin{table}{section}
\renewcommand\thefigure{\thesection.\arabic{figure}}
\titleclass{\section}{top}
\newcommand\sectionbreak{\cleardoublepage}
\titleformat{\section}[display]
{\gdef\thissectiontitle{##1}\gdef\thissectionnumber{\thesection}%
    \global\toggletrue{noFigs}\normalfont\huge\bfseries}{\chaptertitlename\ \thesection}{20pt}{\Huge##1}
\titlespacing*{\section}
  {0pt}{50pt}{40pt}
\titleformat{\subsection}
  {\normalfont\Large\bfseries}{\thesubsection}{1em}{##1}
\titlespacing*{\subsection}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
}
\makeatother

% % % % % % % % % % RAPPORT % % % % % % % % % % % % % 
\begin{document}

\listoffigures
\newpage

% chapter 1:
\chapter{Introduction}
\section{Problem overview}
\begin{figure}[H]
    \caption{Comparative table 1}
\end{figure}

\section{Application description}
\begin{figure}[H]
    \caption{Comparative table 2}
\end{figure}
\newpage
% end chapter 1 

% appendices
\appendix
\clearpage % or \cleardoublepage
\appendixpage
\addappheadtotoc
% code to show appendices at section level in TOC
\begin{appendices}
\changesections
\section{Installation requirements}    
\subsection{Strahov}
\section{Performance evaluation I appendix}     

\subsection{University laboratory}
\begin{figure}[H]
    \caption{Comparative table 4}
\end{figure}
\begin{figure}[H]
    \caption{Comparative table 3}
\end{figure}

\end{appendices}
% end appendices

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .