新称号等级不增加计数器

新称号等级不增加计数器

我对 LaTeX 还不熟悉,需要在文档中创建一个子子节。经过一番寻找,我发现可以用 来完成titlesec。我按照能找到的所有说明操作,但仍然无法按我的要求工作。

子子节出现在目录中,使用时计数器确实有效,\setcounter{}{}并且它还会重置每个子子节,但由于某种原因,计数器不会随着新的子子节的增加而增加,也不会thesubsubsubsection显示在目录或文本中。

下面是代码和文档。最终目录可能只会显示 2 个级别,所以我现在并不关心那里的外观。它只是为了显示子子子节以某种方式被识别。

\documentclass[11pt,twoside,a4paper]{article}

\usepackage{titlesec}

\titleclass{\subsubsubsection}{straight}[\subsubsection]
\newcounter{subsubsubsection}[subsubsection]
\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}
\titlespacing*{\subsubsubsection}{0mm}{0mm}{0mm}[0mm]
\titleformat{\subsubsubsection}{\small}{\thesubsubsubsection}{1em}{}

\begin{document}

\tableofcontents

\section{Section one}
\subsection{Subsection one}
\subsubsection{Subsubsection one}
\subsubsubsection{Subsubsubsection one}
\thesubsubsubsection\\
\setcounter{subsubsubsection}{3}
\thesubsubsubsection
\subsubsection{Subsubsection two}
\subsubsubsection{Subsubsubsection one}
\thesubsubsubsection\\

\end{document}

在此处输入图片描述

答案1

您必须更改值secnumdepth(默认情况下,章节标题的编号最高为 3 级 - 子子章节的级别)。您还必须通过以下方式设置目录中子子子章节的布局titletoc

\documentclass[11pt, twoside, a4paper]{article}

\usepackage{titlesec}
\setcounter{secnumdepth}{4}
\titleclass{\subsubsubsection}{straight}[\subsubsection]
\newcounter{subsubsubsection}%[subsubsection]
\counterwithin{subsubsubsection}{subsubsection}
\titlespacing*{\subsubsubsection}{0mm}{0mm}{0mm}[0mm]
\titleformat{\subsubsubsection}{\small}{\thesubsubsubsection}{1em}{}

\begin{document}

\tableofcontents

\section{Section one}
\subsection{Subsection one}
\subsubsection{Subsubsection one}
\subsubsubsection{Subsubsubsection one}
\thesubsubsubsection\\
\setcounter{subsubsubsection}{3}
\thesubsubsubsection
\subsubsection{Subsubsection two}
\subsubsubsection{Subsubsubsection one}
\thesubsubsubsection

\end{document}

在此处输入图片描述

相关内容