對節、小節、小節進行編號

對節、小節、小節進行編號

我正在使用該類book,並且對於每個章節、章節、小節等,編號都是這樣開始的:

第1章

第 1.1 節

第 1.2 節

第 1.3 節。 。 。

我想要這樣的東西:

第1章

第 1.0 節

第 1.1 節

第 1.2 節

有什麼建議麼?非常感謝你的幫忙。

答案1

您可以重新定義\thesection,使其發出目前數字減一。

\documentclass{book}

\makeatletter
\renewcommand{\thesection}{%
  \thechapter.\@arabic{\numexpr\c@section-1}%
}
\makeatother

\begin{document}
\tableofcontents

\chapter{First chapter}

\section{First section}
\section{Second section}
\section{Third section}

\chapter{Second chapter}

\section{First section}
\section{Second section}
\section{Third section}

\end{document}

在此輸入影像描述

答案2

\chapter調用\@chapter,它\refstepcounter(在mainmatter模式下)——這意味著章節計數器的重置列表上的任何計數器都重置為零,當然對於計數器來說section也是如此。

要么\@chapter重新定義,要么可以添加一些額外的程式碼,將節計數器設定為-1refstepping 完成後的值。

請注意:這確實不是將計數器設定subsection為-1等。

\documentclass{book}
\usepackage{xpatch}

\makeatletter
\AtBeginDocument{%
\xpatchcmd{\@chapter}{%
  \refstepcounter{chapter}%
}{%
  \refstepcounter{chapter}%
  \setcounter{section}{-1}%
}{\typeout{Success}}{}
}
\makeatother

\begin{document}
\tableofcontents

\chapter{First chapter}

\section{First section}

\section{Second section}
\section{Third section}

\chapter{Second chapter}

\section{First section}

\section{Second section}

\section{Third section}


\end{document}

在此輸入影像描述

這是一個級聯到的版本\subparagraph

\documentclass{book}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@sect}{%
  \refstepcounter{#1}%
}{%
  \refstepcounter{#1}%
  % Now use the \@elt - trick to set all depending counters to -1 (well even that one that shouldn't, most likely :-()
  \def\@elt##1{\setcounter{##1}{-1}}
  \csname cl@#1\endcsname%
}{}{}


\AtBeginDocument{%
  \xpatchcmd{\@chapter}{%
    \refstepcounter{chapter}%
  }{%
    \refstepcounter{chapter}%
    \setcounter{section}{-1}%
   }{\typeout{Success}}{\typeout{Failed!}}
}
\makeatother

\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
\begin{document}
\tableofcontents

\chapter{First chapter}

\section{First section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\paragraph{First paragraph}
\subparagraph{First subparagraph}


\section{Second section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\paragraph{First paragraph}
\subparagraph{First subparagraph}

\section{Third section}

\chapter{Second chapter}

\section{First section}

\section{Second section}

\section{Third section}


\end{document}

答案3

您可以對每個部分執行以下操作:

\setcounter{section}{-1}

註:我最初是\setcounter{section}{0}在回答時寫的。

相關內容