根据包含实体对段落进行编号

根据包含实体对段落进行编号

有没有办法让段落在章节层次中处于不同的深度?

例如,在我的论文背景章节中,我不需要五个级别(章节/章节/小节/小小节/段落)。在数学陈述的主体中,我至少需要这么多。

我希望对各个级别的段落进行相同的处理:

  • 段落无目录条目
  • 相同的标题样式(斜体,不是粗体,适用于amsbook类)

但我希望编号能够适应包含实体。目前,如果我不使用小节和小小节,段落编号就会变成零,甚至更糟(它会尝试记住我拥有的最后一个小小节的编号)。

\chapter{This is chapter 1}

\section{This is section 1}
Content

   \subsection{This is subsection 1.1}
   Content

      \subsubsection{This is subsubsection 1.1.1}
      Content

         \paragraph{This is paragraph 1.1.1.1}
         Content

\section{This is section 2}
Content

    \paragraph{I would like this paragraph to be 2.1}
    Content

\section{This is section 3}
Content

   \subsection{This is subsection 3.1}
   Content

      \paragraph{I would like this to be paragraph 3.1.1}
      Content

这种编号方式可行吗?是否可以自动完成,还是每次将段落置于不同级别时都需要重新定义段落样式?

答案1

我不确定这是不是好的风格。更好的是,我确信这是不是好作风。;-)

\documentclass{amsbook}

\usepackage{etoolbox,chngcntr}

\makeatletter
% at \@startsection, set also the level we're at
\pretocmd{\@startsection}{\setcounter{voigtlevel}{#2}}{}{}
\makeatother

\newcounter{voigtlevel} % keeps track of the current level

% all counters should be reset when an ancestor is stepped
\counterwithin*{paragraph}{chapter}
\counterwithin*{paragraph}{section}
\counterwithin*{paragraph}{subsection}
\counterwithin*{subsubsection}{chapter}
\counterwithin*{subsubsection}{section}
\counterwithin*{subsection}{chapter}

% redefine \theparagraph
\renewcommand{\theparagraph}{%
  \ifcase\value{voigtlevel}\or
    \thesection.\arabic{paragraph}\or
    \thesection\zarabic{subsection}.\arabic{paragraph}\else
    \thesection\zarabic{subsection}\zarabic{subsubsection}.\arabic{paragraph}\fi
}
% print no number (and no period) if the counter is 0
\newcommand{\zarabic}[1]{\ifnum\value{#1}=0 \else.\arabic{#1}\fi}

% sections don't have the chapter number
\renewcommand{\thesection}{\arabic{section}}

% paragraphs are numbered
\setcounter{secnumdepth}{4}

\begin{document}
\mainmatter
\chapter{This is chapter 1}

\section{This is section 1}
Content

   \subsection{This is subsection 1.1}
   Content

      \subsubsection{This is subsubsection 1.1.1}
      Content

         \paragraph{This is paragraph 1.1.1.1}
         Content

\section{This is section 2}
Content

    \paragraph{I would like this paragraph to be 2.1}
    Content

\section{This is section 3}
Content

   \subsection{This is subsection 3.1}
   Content

      \paragraph{I would like this to be paragraph 3.1.1}
      Content
\end{document}

在此处输入图片描述

答案2

我稍微整理了一下 egreg 的解决方案,将其扩展到涵盖子段落,同时解决了 amsbook 中对计数器支持不完整的烦恼tocdepth

而且我去掉了voigtlevel计数器,因为它完全是多余的zarabic

\usepackage{chngcntr}

% place subsubsection, paragraph, and subparagraph at distinct values of tocdepth
% amsbook default is for all to share level 3
\makeatletter
\def\l@paragraph{\@tocline{4}{0pt}{1pc}{9pc}{}}
\def\l@subparagraph{\@tocline{5}{0pt}{1pc}{11pc}{}}
\makeatother

% all counters should be reset when an ancestor is stepped
\counterwithin*{subparagraph}{chapter}
\counterwithin*{subparagraph}{section}
\counterwithin*{subparagraph}{subsection}
\counterwithin*{subparagraph}{subsubsection}
\counterwithin*{paragraph}{chapter}
\counterwithin*{paragraph}{section}
\counterwithin*{paragraph}{subsection}
\counterwithin*{subsubsection}{chapter}
\counterwithin*{subsubsection}{section}
\counterwithin*{subsection}{chapter}

% print no number (and no period) if the counter is 0
\newcommand{\zarabic}[1]{\ifnum\value{#1}=0 \else.\arabic{#1}\fi}

% redefine \theparagraph
\renewcommand{\theparagraph}{%
    \thesection\zarabic{subsection}\zarabic{subsubsection}.\arabic{paragraph}%
}
\renewcommand{\thesubparagraph}{%
    \thesection\zarabic{subsection}\zarabic{subsubsection}\zarabic{paragraph}.\arabic{subparagraph}%
}

相关内容