在一个上一个问题,我问如何才能从枚举中自动生成本地目录,而目录只会选择枚举的标题(这已通过 etoc 包解决)。现在我想在枚举的项目之间写入一些命令,以便在本地目录的相应条目之间出现分隔符(例如空白行)。
例子:
\myitem{Fact 1} Explanation 1
\myitem{Fact 2} Explanation 2
\separatehere
\myitem{Fact 3} Explanation 3
\myitem{Fact 4} Explanation 4
应生成目录
事实 1
事实 2
[此处空白]
事实 3
事实 4
答案1
这是实现此目的的一种方法。目的是在.toc
文件中插入仅针对特定本地目录执行的内容。
etoc 仅对所有本地目录使用标准目录文件)
有多种方法可以做到这一点,我在这里使用了一个技巧,即定义一个只有 etoc 才能看到的额外虚拟切片级别。
\documentclass{article}
\usepackage{etoc}
\usepackage{hyperref}
\makeatletter
\etocsetlevel{myitem}{6}% dummy sectioning level
\etocsetlevel{myitemseparator}{6}% dummy thing will be used for
% injecting code in TOC executed
% ONLY when we want it executed
\newcommand\mylistofitems{%
\begingroup
\etocsetlevel{subsection}{6}% ignore real subsections (level 2)
\etocsetlevel{subsubsection}{6}% ignore subsubsections (level 3)
\etocsetlevel{myitem}{2}% because this is used in \section (level 1)
\etocsetlevel{myitemseparator}{3}% because this is used in \section (level 1)
%
\etocsetnexttocdepth{myitemseparator}%
\etocsettocstyle{}{}%
% to avoid problem on first compilation (missing \item), we do not insert
% the \begin{enumerate} in \etocsettocstyle arguments,
% but directly here.
%
% Note: one could have hoped that putting it in \etocsettocstyle
% and issueing \etocchecksemptiness would have worked. But alas,
% the etoc doc says:
% For a finalized document compiled with initially no
% auxiliary files, the first LaTeX run will declare all local
% TOCs non empty and print for each of them a heading (and no
% contents naturally).
% This is bad here, because empty enumerate environment
% raises LaTeX error.
\etocsetstyle{myitem}
{\begin{enumerate}}
{}
{\item\textbf{\etocname}}
{\end{enumerate}}%
\etocsetstyle{myitemseparator}
{}
{\par\addvspace{\myextraspace}}
{}
{}%
\subsection*{Linked list of definitions}
\localtableofcontents
\hrule
\endgroup
}
\makeatother
\newcommand\myitem[1]{\item\textbf{#1:}\etoctoccontentsline{myitem}{#1}}
\newlength\myextraspace
\setlength\myextraspace{12pt}
\newcommand\separatehere{\etoctoccontentsline{myitemseparator}{}}
\begin{document}
\tableofcontents
\section{SECTION 1}
\mylistofitems
\begin{enumerate}
% don't use colons at end of item titles here
\myitem{Linear cones} Let $F$ be an ordered field and $V$ an $F$-vector space. A \emph{linear cone} $C$ is a subset of $V$ closed under positive scalar products.
\myitem{Partial order defined by a convex cone} If $C$ is a pointed salient convex cone, then the relation $x\leq y$ iff $y-x\in C$ is a partial order.
\separatehere
\myitem{Dual cone} Let $S$ be any subset of a vector space $V$ over an ordered field. The \emph{dual cone} $S^*$ of $S$ is the convex cone
$$S^*:=\{v\in V \ | \ \langle v,x\rangle\geq0 \ \forall x\in S\}.$$
\end{enumerate}
\end{document}
给予
完全可以\separatehere
接受一些(可选的,也许是)参数,这将表明最后的 TOC 中的自定义分离级别。
像往常一样,有两个汇编,包含目录
请注意,代码用于列出位于章节下方顶层的项目。如果您需要它们位于子章节下方,则需要稍微调整一下代码。
变体使用amsart
\documentclass{amsart}
\usepackage{etoc}
% avoid clash with amsart
% https://tex.stackexchange.com/questions/423110/can-one-use-etoc-with-amsart
\etocsettocstyle{\noindent\textbf{\contentsname}\par}{}
\usepackage{hyperref}
\makeatletter
\etocsetlevel{myitem}{6}% dummy sectioning level
\etocsetlevel{myitemseparator}{6}% dummy thing will be used for
% injecting code in TOC executed
% ONLY when we want it executed
\newcommand\mylistofitems{%
\begingroup
\etocsetlevel{subsection}{6}% ignore real subsections (level 2)
\etocsetlevel{subsubsection}{6}% ignore subsubsections (level 3)
\etocsetlevel{myitem}{2}% because this is used in \section (level 1)
\etocsetlevel{myitemseparator}{3}% because this is used in \section (level 1)
%
\etocsetnexttocdepth{myitemseparator}%
\etocsettocstyle{}{}%
% to avoid problem on first compilation (missing \item), we do not insert
% the \begin{enumerate} in \etocsettocstyle arguments,
% but directly here.
%
% Note: one could have hoped that putting it in \etocsettocstyle
% and issueing \etocchecksemptiness would have worked. But alas,
% the etoc doc says:
% For a finalized document compiled with initially no
% auxiliary files, the first LaTeX run will declare all local
% TOCs non empty and print for each of them a heading (and no
% contents naturally).
% This is bad here, because empty enumerate environment
% raises LaTeX error.
\etocsetstyle{myitem}
{\begin{enumerate}}
{}
{\item\textbf{\etocname}}
{\end{enumerate}}%
\etocsetstyle{myitemseparator}
{}
{\par\addvspace{\myextraspace}}
{}
{}%
\noindent\textbf{Linked list of definitions}\par
\localtableofcontents
\hrule
\endgroup
}
\makeatother
\newcommand\myitem[1]{\item\textbf{#1:}\etoctoccontentsline{myitem}{#1}}
\newlength\myextraspace
\setlength\myextraspace{12pt}
\newcommand\separatehere{\etoctoccontentsline{myitemseparator}{}}
\begin{document}
\tableofcontents
\section{SECTION 1}
\mylistofitems
\begin{enumerate}
% don't use colons at end of item titles here
\myitem{Linear cones} Let $F$ be an ordered field and $V$ an $F$-vector space. A \emph{linear cone} $C$ is a subset of $V$ closed under positive scalar products.
\myitem{Partial order defined by a convex cone} If $C$ is a pointed salient convex cone, then the relation $x\leq y$ iff $y-x\in C$ is a partial order.
\separatehere
\myitem{Dual cone} Let $S$ be any subset of a vector space $V$ over an ordered field. The \emph{dual cone} $S^*$ of $S$ is the convex cone
$$S^*:=\{v\in V \ | \ \langle v,x\rangle\geq0 \ \forall x\in S\}.$$
\end{enumerate}
\end{document}
布局需要一些微调(在水平线后添加空间等)。
特别是,最好在这里添加一些代码以避免在“定义列表”之后立即出现分页符。(\subsection
在 amsart 案例中我们不再使用)。可能有些\nopagebreak[4]
。