我定义了一个new command
,这样我就可以得到我想要的格式enumeration
的subsections
。现在我的问题是我不知道如何让这些数字及其相应的标题出现在目录(\tableofcontents
)上。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{report}
\usepackage{ulem}
\begin{document}
\tableofcontents
\newcounter{UntUntKap}[section]
\newcommand{\nummeriere}[1]{\stepcounter{UntUntKap}\uline{\arabic{chapter}.\arabic{section}.\arabic{UntUntKap}} \ #1}
\section{erste}
\nummeriere{ das ist text } \\
\nummeriere \\
\nummeriere\\
\nummeriere
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
我尝试过\addcontentsline{toc}{subsection}{*}
,但要么是我使用错误,要么是这个命令不接受我的“ \nummeriere
”。我的最佳方案是“ add to toc
”包含在我的自定义命令中,但如果我每次都必须写它,我想我也可以创建一个更简单的命令...
非常感谢您的帮助!
答案1
如果你想改变正文和目录中章节的格式,可以使用标题安全和标题目录你可能会感兴趣
如果你想“手动”操作,则不需要以下软件包:
下面的切片计数器的通常层次结构chapter
是:
section
→ subsection
→ subsubsection
→ paragraph
→ subparagraph
。
相应的sectionig命令是:
\section
→ \subsection
→ \subsubsection
→ \paragraph
→ \subparagraph
。
所有这些都表示章节。“小节”、“子小节”、“段落”等只是 LaTeX 术语,用于表示不同级别的章节。
您的计数器UntUntKap
与 -counter 表示相同的分段级别subsection
。
因此,我不会定义一个\nummeriere
连接到与连接到 -command 的编号基础设施并行的编号基础设施的 -command,而是\subsection
定义我自己的\subsection
-command 定制变体,该变体使用与 -command 相同的编号基础设施\subsection
。
是因为它可能。
您可以实现与连接到 -command 的编号基础设施并行的编号基础设施,\subsection
如下所示:
\documentclass{report}
%\usepackage{hyperref}
\usepackage{ulem}
\setcounter{secnumdepth}{2} % 1 -> sections are the last sectioning-level that gets numbered.
% 2 -> subsections are the last sectioning-level that gets numbered.
% 3 -> subsubsections are the last sectioning-level that gets numbered.
% etc
\setcounter{tocdepth}{2} % 1 -> sections go to toc
% 2 -> sections and subsections go to toc
% 3 -> sections, subsections and subsubsections go to toc
% etc
\newcounter{UntUntKap}[section]
\renewcommand\theUntUntKap{\thesection.\arabic{UntUntKap}}%
\makeatletter
\AtBeginDocument{\let\l@UntUntKap=\l@subsection}%
\newcommand\CheckWhetherArgumentIsEmpty[1]{%
\romannumeral0%
\ifcat A\detokenize{#1}A%
\@firstoftwo{\expandafter\expandafter\expandafter}{} %
\expandafter\@firstoftwo
\else
\@firstoftwo{\expandafter\expandafter\expandafter}{} %
\expandafter\@secondoftwo
\fi
}%
\newcommand\nummeriere{%
\@ifstar\nummeriere@star\nummeriere@nostar
}%
\newcommand{\nummeriere@star}[1][]{%
#1\@bsphack\@esphack
}%
\newcommand{\nummeriere@nostar}[1][]{%
\ifnum 2>\c@secnumdepth\else
\refstepcounter{UntUntKap}%
\underline{\theUntUntKap}%
\addcontentsline{toc}{UntUntKap}{%
\ifnum2>\c@secnumdepth\else
\protect\numberline{\theUntUntKap}%
\fi
\CheckWhetherArgumentIsEmpty{#1}{\protect\kern-.6em}{#1}%
}%
\space
\fi
#1%
\@bsphack\@esphack
}%
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}
\enlargethispage{2\baselineskip}%
\section{A section whose hierarchy-level is named ``section'' in \LaTeX-jargon.}
\subsection{A section whose hierarchy-level is named ``subsection'' in \LaTeX-jargon.}
\nummeriere[This is text belonging to a numbering-structure, not really a sectioning-structure,
which is parallel to the numbering of subsections that goes to the toc as well.]
This is text belonging to a numbering-structure, not really a sectioning-structure,
which is parallel to the numbering of subsections that does not go to the toc.\\
\nummeriere This is text belonging to a numbering-structure, not really a sectioning-structure,
which is parallel to the numbering of subsections that does not go to the toc.
\nummeriere This is text belonging to a numbering-structure, not really a sectioning-structure,
which is parallel to the numbering of subsections that does not go to the toc. %%%
\nummeriere This is text belonging to a numbering-structure, not really a sectioning-structure,
which is parallel to the numbering of subsections that does not go to the toc.\
\bigskip
Having two parallel numbering-structures, namely the numbering-structure that belongs to sections
whose hierarchy-level is named ``subsection'' in \LaTeX-jargon and the numbering-structure that
underlies the \verb|\nummeriere|-command is confusing.
Unless you never use them parallel throughout the whole document.
I.e.:
\begingroup\sloppy
When you have two consecutive \verb|\section|s with \verb|\subsection|s/\allowbreak\verb|\subsubsection|s/\allowbreak etc
in between, then there should not also be \verb|\nummeriere| in between.
When you have two consecutive \verb|\section|s with \verb|\nummeriere| in between, then
there should not also be \verb|\subsection|s/\allowbreak\verb|\subsubsection|s/\allowbreak etc in between.
\endgroup
\end{document}