セクション、サブセクション、サブサブセクションの番号付け

セクション、サブセクション、サブサブセクションの番号付け

私はクラスを使用しておりbook、各章、セクション、サブセクションなどの番号付けは次のように始まります。

第1章

セクション1.1

セクション1.2

セクション 1.3 . . .

代わりに次のようなものを希望します:

第1章

セクション 1.0

セクション1.1

セクション1.2

何か提案はありますか?ご協力ありがとうございます。

答え1

\thesection現在の数値から 1 を引いた数値を発行するように再定義できます。

\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を実行します。つまり、チャプター カウンターのリセット リストにあるすべてのカウンターがゼロにリセットされることを意味します。もちろん、カウンターの場合も同様です。\refstepcountermainmattersection

どちらかが再定義されるか、または、 refstepping が完了した後に\@chapterセクション カウンターを設定する追加コードを追加することができます。-1

注意:これはない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}回答時に書きました。

関連情報