如何在 LOF 中包含附录名称?

如何在 LOF 中包含附录名称?

如果附录包含数字,我想知道如何在 LOF 中显示附录的名称。

    % % % % % % % % % % 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}

现在,LOF 显示如下:

劳伦斯

请注意,如果章节包含图形,则在 LOF 中显示章节名称的代码片段,以及使附录的部分看起来像章节和小节看起来像文档正文中的部分的代码片段。

答案1

需要做一些修改;我使用了一个布尔开关,appendices最初设置为 false;如果开关为 false,则章节的信息将添加到 LoF;如果开关为 true,则修改部分的信息将包含在 LoF 中;为了轻松访问标题,我还使用了以下explicit选项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}

在此处输入图片描述

相关内容