开始新的章节、小节等时,\subsubsubsection、\paragraph 和 \subparagraph 计数不会重置

开始新的章节、小节等时,\subsubsubsection、\paragraph 和 \subparagraph 计数不会重置

我正在尝试在我的文章中使用小节、小节、小节小节、段落和小段落,并且我使用下面给出的代码。

如何在 \subsubsection 下添加带有标题的额外层级

解决方案发布如下:

开始新的章节、小节等时,\subsubsubsection 计数不会重置

但我仍然无法获得正确的编号。

我承认我使用 article 类是因为我是 Latex 新手,对其他类不太了解。另外,有些人会说我不需要这么多缩进,但不幸的是,在我的报告中,我想在目录中显示 9 级缩进。

以下是我的 MWE

\documentclass{article}
\usepackage{titlesec}
\usepackage[utf8]{inputenc}
\usepackage[hidelinks]{hyperref}
\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}[subsubsection]

\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}}
\renewcommand\thesubparagraph{\theparagraph.\arabic{subparagraph}}

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}
\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother

\makeatletter
\@addtoreset{subsubsubsection}{section}
\@addtoreset{subsubsubsection}{subsection}
\makeatother

\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{6}

\author{Author}
\title{Title}
\date{2014}

\begin{document}
\maketitle
\newpage
\tableofcontents
\newpage
\section{Section 1}
\subsection{subsection 1}
\subsubsection{subsubsection 1}
\subsubsubsection{Subsubsubsection 1}
Some description here
\paragraph{paragraph 1}
Some description here
\paragraph{Paragraph 2}
Some description here
\subsubsubsection{subsubsubsection 2}
Description here
\subsubsubsection{subsubsubsection 3}
description here
\subsubsubsection{subsubsubsection 4}
description here
\paragraph{paragraph 1} 
Some description here
\paragraph{paragraph 2}
some description here
\paragraph{Paragraph 3}
\subsubsubsection{subsubsubsection 5}
description here

\end{document}

PDF 结果

从目录中可以看出,第 4 个子小节下的第 1 段从 1.1.1.4.3 开始(我希望它从 1.1.1.4.1 开始)同样,第 4 个子小节下的第 2 段应该分别从 1.1.1.4.2 开始。

答案1

当前的问题是,当你开始新的 subsubsubsection 时,你需要重置段落计数器。为此,你需要做的就是添加:

\@addtoreset{paragraph}{subsubsubsection}

但请注意,您可能还会发现需要根据文档的结构添加一些进一步的重置。

更一般地说,我不得不说,你发现需要这样做这一事实向我表明你需要重新考虑文档的结构。即使你正在写一本书或一篇论文(这article不适合作为课程),9 个级别也只会让人感到困惑。唯一的例外可能是法律文件,它似乎确实需要疯狂的层次结构。我认为你真的应该问一问,你希望读者从结构中获得什么清晰度。如果答案是没有,或者更糟的是,更复杂和更混乱,你知道你需要重新思考。

但是,这是 TeX SE,因此我可以问心无愧地提供“解决方案”,因为该网站的业务不是确保人们写得好,而只是帮助他们用 TeX 写作。

\documentclass{article}
\usepackage{titlesec}
\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}[subsubsection]

\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}}
\renewcommand\thesubparagraph{\theparagraph.\arabic{subparagraph}}

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}
\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\@addtoreset{subsubsubsection}{section}
\@addtoreset{subsubsubsection}{subsection}
\@addtoreset{paragraph}{subsubsubsection}
\makeatother

\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{6}

\author{Author}
\title{Title}
\date{2014}

\begin{document}
\tableofcontents

\section{Section 1}
\subsection{subsection 1}
\subsubsection{subsubsection 1}
\subsubsubsection{Subsubsubsection 1}
Some description here
\paragraph{paragraph 1}
Some description here
\paragraph{Paragraph 2}
Some description here
\subsubsubsection{subsubsubsection 2}
Description here
\subsubsubsection{subsubsubsection 3}
description here
\subsubsubsection{subsubsubsection 4}
description here
\paragraph{paragraph 1}
Some description here
\paragraph{paragraph 2}
some description here
\paragraph{Paragraph 3}
\subsubsubsection{subsubsubsection 5}
description here

\end{document}

TOC 显示含量过高

相关内容