自定义编号列表,其中包含部分和包含这些部分和列表标题的目录

自定义编号列表,其中包含部分和包含这些部分和列表标题的目录

我正在寻找一种方法来创建自定义目录(用于附录和附件),该目录将与主目录分开,并包含为此表定义的部分以及插入的所有标题的列表。我不确定这是否很清楚,所以这是我想要的表示:

Main table of content

    * standard table of content with both 'Annexes' and 'Appendices' sections. *

List of example %for the sake of example but it would be annexes and appendices
A. Code snippets
A.1. Title of the example containing the first code snippets
A.2. Title of the ''      ''         ''  second ''  ''

B. Raw data
B.1. Title of the example containing the first raw data
B.2. Title of the ''      ''         ''  second ''  ''

And so on...

当我在网上寻找解决方案时,我发现了一个有趣的答案:使用 tocloft 创建单独的附录列表。这样就可以为我的文档自定义目录。我通过添加hyperref包来“修改”代码,以便拥有 pdf 书签。

\documentclass[twoside, a4paper]{article} % CHANGED, USED TO BE " \documentclass[toc=flat,numbers=noenddot]{scrartcl}"

\usepackage[english]{babel}% "english" INSTEAD OF "ngerman"
\usepackage{blindtext}

\usepackage{hyperref} % ADDED: To generate hyperlinks in the TOC

\makeatletter
\newcommand*{\maintoc}{% main table of contents
  \begingroup
    \@fileswfalse% don't open new ToC file
    \renewcommand*{\appendixattoc}{% macro for separation of ToC contents
      \value{tocdepth}=-10000 % set tocdepth to very small value locally
    }%
    \tableofcontents% output ToC
  \endgroup
}
\newcommand*{\appendixtoc}{% table of contents for appendix
  \begingroup
    \edef\@alltocdepth{\the\value{tocdepth}}% save tocdepth
    \setcounter{tocdepth}{-10000}% no ToC entries
    \renewcommand*{\contentsname}{% change ToC name
      List of Appendices}% "List of Appendices" INSTEAD OF "Verzeichnis der Anh\"ange"
    \renewcommand*{\appendixattoc}{% macro for separation of ToC contents
      \setcounter{tocdepth}{\@alltocdepth}% restore tocdepth
    }%
    \tableofcontents% output ToC
    \setcounter{tocdepth}{\@alltocdepth}% restore tocdepth
  \endgroup
}
\newcommand*{\appendixattoc}{% macro for separation of ToC contents
}
\g@addto@macro\appendix{% augment \appendix
%  \if@openright\cleardoublepage\else\clearpage\fi% new page; DELETED
  \clearpage% new page; ADDED
  \addcontentsline{toc}{section}{\appendixname}% entry into main ToC;
%     "section" INSTEAD OF "chapter"
  \addtocontents{toc}{\protect\appendixattoc}% macro for separation into ToC file
  \renewcommand*{\thesection}{Appendix~\Alph{section}}% ADDED
}
\makeatother

\begin{document}

\maintoc
\blinddocument

\appendix
\appendixtoc
\blinddocument

\end{document}

% Note that \maintoc only works if \appendixtoc is also present. Otherwise,
% the ToC will never be updated. If \appendixtoc is removed, one should use
% \tableofcontents instead of \maintoc.

我的第二步是制作自定义列表。为此,我惊奇地发现了这个问题:新品计数器列表包含创建自定义列表所需的代码,该列表的名称中包含部分编号。我稍微修改了源代码以更改标题的格式(居中标题、列表名称的小写字母、编号和标题用“-”分隔,标题编号后没有句点。

% !TEX program = lualatex 

\documentclass[twoside, a4paper]{article} % Option [twoside] utile pour la création d'en-tête différentes entre pages paires et impaires

\usepackage{blindtext}
\usepackage{tocloft}
\usepackage{lmodern}

\usepackage{etoolbox}

% SMALL CAPS 
% NEW LINE AFTER TITLE AND NUMBER PRECEDED WITH '-' 
% CENTER CAPTION
% NO PERIOD AFTER CAPTION NUMBERING
\newcounter{example}[section]
\renewcommand{\theexample}{\arabic{section}.\arabic{example}}
\newenvironment{example}[1][]{%
  \refstepcounter{example}%
  \ifblank{#1}{}{%
    \addcontentsline{exp}{examples}{\protect\numberline{\theexample}#1}%
  }%
  \par\medskip
  \begin{center}
    \textsc{Example~\theexample}\ifblank{#1}{}{~--~#1}
  \end{center}
}{\medskip}

\newcommand{\listexampletitle}{List of Examples}

\newlistof[section]{examples}{exp}{\listexampletitle}%

\cftsetindents{examples}{1.5em}{3.0em}%
\setlength{\cftexamplesnumwidth}{1.5cm}



\begin{document}

\section{Introduction}%

\listofexamples

\begin{example}[First title]
This is the first example. The counter will be reset at each section.
\end{example}

\

\begin{example}[]
This is the 2nd  example, but has no entry to the toc!
\end{example}


\section{A section}
\blindtext[1]
\begin{example}[Another title]
\blindtext[2] 

Another example.
\end{example}


\begin{example}[Yet Another title]
\blindtext[3]% 

Yet Another example.
\end{example}

\end{document}

然而,我必须承认,我不知道如何“组合”这两个代码片段来创建所需的结果。我甚至不知道这是否有可能。

我愿意接受各种帮助,谢谢。

相关内容