书籍:章节/部分/小节编号

书籍:章节/部分/小节编号

我是 LaTeX 新手,但想尝试将我的线性代数讲座转为文本格式。我的讲师使用以下结构:

第 0 章:基础知识

  • § 1 套
    • 定义 1.1:一些定义
    • 定义 1.2:一些定义
    • Pro. 1.3:一些命题
    • 例 1.4:一些例子
  • § 2 其他部分
  • § 3 其他部分
    • 定义 3.1:一些定义
    • 定义 3.2:一些定义
    • Pro. 3.3:一些命题
    • 例 3.4:一些例子
  • § 4 其他部分

第一章:群、环和域

  • § 5 团体
    • 定义 5.1:一些定义
    • ...
  • § 6 环

文字结构:

  • 章节
    • 编号(从 0 开始)
  • 章节(分章)
    • 编号
    • 不受章节编号影响
    • 新章节开始时不要重置
    • 以 § 符号开头
  • 小节(定义、例子、命题)
    • 以当前章节编号为前缀
    • 重置每个新部分

如果能写出这样的内容就太好了:

\documentclass{book}
...


\begin{document}

\chapter{Basics}

\section{Sets}
\subsection{Def. :}
Some definition.

\subsection{Example :}
Some example.


\section{NewSection}
....


\chapter{Groupds, Rings, Fields}

\section{Groups}

\subsection{Def. :}
Some definition

...

\end{document}

该行为与期望行为的不同之处在于:章节编号从 1 开始,节编号每章重置一次。节不会自动以 § 符号开头。子节包含章节/节和子节编号。

我怎样才能获得我想要的布局?

答案1

如果对节进行编号而与章节无关,则会出现一个问题:如何对放在章节中但未放在节中的定义/命题/示例进行编号?

例如:

Chapter 0 Basics
  1 Elements
  2 Combinations
    Def. 2.1: Some definition
    Def. 2.2: Some definition    
    Pro. 2.3  Some proposition
    Exm. 2.4: Some Example
    2.1 Permutations
    2.2 Sets
      Def. 2.2.1: Some definition
      Def. 2.2.2: Some definition
      Pro. 2.2.3  Some proposition
      Exm. 2.2.4: Some Example
Chapter 1 Groups
  Def. <???>1: Some definition
  Pro. <???>2  Some proposition
  Exm. <???>3: Some Example
  3 Groups
    Def. 3.1: Some definition
    Pro. 3.2  Some proposition
    Exm. 3.3: Some Example
Chapter 2 Rings and Fields  
  Def. <???>1: Some definition
  Pro. <???>2  Some proposition
  Exm. <???>3: Some Example
  4 Rings 
  5 Fields    

第 1 章中的定义/命题/例子应该如何命名?
它们不属于第 2 节。它们也不属于第 3 节。

第 2 章中的定义/命题/例子应该如何命名?它们不属于第 3 节。它们也不属于第 4 节。

<???>=<chapter>/<definition/proposition/example number>对于这些情况我建议:

Chapter 0 Basics
  1 Elements
  2 Combinations
    Def. 2.1: Some definition
    Def. 2.2: Some definition
    Pro. 2.3  Some proposition
    Exm. 2.4: Some Example
    2.1 Permutations
    2.2 Sets
      Def. 2.2.1: Some definition
      Def. 2.2.2: Some definition
      Pro. 2.2.3  Some proposition
      Exm. 2.2.4: Some Example
Chapter 1 Groups
  Def. 1/1: Some definition
  Pro. 1/2  Some proposition
  Exm. 1/3: Some Example
  3 Groups
    Def. 3.1: Some definition
    Def. 3.2: Some definition        
    Pro. 3.3  Some proposition
    Exm. 3.4: Some Example
Chapter 2 Rings and Fields
  Def. 2/1: Some definition
  Pro. 2/2  Some proposition
  Pro. 2/3  Some proposition      
  Exm. 2/4: Some Example
  4 Rings
  5 Fields

另一个问题是关于脚注、表格、图表和方程式的编号。

我建议按章节对脚注进行编号。
我建议按节对表格、图表和方程式进行编号,因为更深的节级可能具有同样编号的定义/命题/示例附属物。

我建议将表格/图形/公式放在章中但不放在节中,其处理方式与将定义/命题/例子放在章中但不放在节中相同,即在相应的数字前面加上“/”。

还有一个问题:

您是否希望定义/命题/示例也出现在目录中?

您是否希望获得类似单独的定义列表/命题列表/示例列表的东西?

我建议不要在目录中出现定义/命题/例子。
我建议不要有单独的定义列表/命题列表/例子列表。
这些事情需要对文档类/书籍类进行更粗暴的破解。

\documentclass{book}
\usepackage{hyperref}
\makeatletter
\newcounter{TheoremElement}
\newcounter{sectionfake}
\begingroup
\def\tempa#1{\global\csname c@#1\endcsname\z@}%
\expandafter\endgroup\ifx\tempa\@stpelt
  \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
  \def\c@sectionfakehack\z@
}{%
  \def\c@sectionfakehack\m@ne\stepcounter#1%
}%
{%
  \let\c@sectionfake\c@sectionfake\stepcounter{sectionfake}%
}%
\renewcommand\cl@chapter{%
  \@elt{sectionfake}%
  \@elt{footnote}%
  \@elt{equation}\@elt{figure}\@elt{table}%
  \@elt{subsection}\@elt{subsubsection}%
  \@elt{paragraph}\@elt{subparagraph}%
  \@elt{TheoremElement}%
}%
\renewcommand\cl@section{%
  \@elt{sectionfakehack}%<-the hack increments sectionfake instead of resetting
                        %  to zero whenever section is incremented via \stepcounter
  \@elt{equation}\@elt{figure}\@elt{table}%
  \@elt{subsection}\@elt{subsubsection}%
  \@elt{paragraph}\@elt{subparagraph}%
  \@elt{TheoremElement}%
}%
\renewcommand\cl@subsection{%
  \@elt{subsubsection}%
  \@elt{paragraph}\@elt{subparagraph}%
  \@elt{TheoremElement}%
}%
\renewcommand\cl@subsubsection{%
  \@elt{paragraph}\@elt{subparagraph}%
  \@elt{TheoremElement}%
}%
\renewcommand\cl@paragraph{%
  \@elt{subparagraph}%
  \@elt{TheoremElement}%
}%
\renewcommand\cl@subparagraph{%
  \@elt{TheoremElement}%
}%
\renewcommand*\cl@TheoremElement{}%
%
\newcommand\sectionfakefork{%
  \ifnum\number\value{sectionfake}>0 %
  \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}%
\newcommand\AllSectionLevelsArabic{%
  \sectionfakefork
  {%
    \AllSectionLevelsArabicLoop{\AllSectionLevelsArabicLoop{%
      \AllSectionLevelsArabicLoop{\AllSectionLevelsArabicLoop{%
        \@firstoftwo{\arabic{section}.}%
      }{subsection}.}{subsubsection}.%
    }{paragraph}.}{subparagraph}.%
    \@firstoftwo
  }{%
    \arabic{chapter}/%
  }%
  \arabic{TheoremElement}%
}%
\newcommand\AllSectionLevelsArabicLoop[4]{%
  #4{\ifnum\number\value{#2}>0 %
     \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
     {#1\@secondoftwo\arabic{#2}#3}{#1#4}%
    }{#1\@secondoftwo\arabic{#2}#3}%
}%
\newcommand\insertbehindnumber[2]{%
  #1\@insertbehimdnumber{#2}%
}%
\newcommand\@insertbehimdnumber{}%
\long\def\@insertbehimdnumber#1#2\endcsname{#2\endcsname#1}%
\renewcommand\theTheoremElement{\AllSectionLevelsArabic}
\newtheorem{definition}[TheoremElement]{\insertbehindnumber{Def.}{:}}%
\newtheorem{proposition}[TheoremElement]{\insertbehindnumber{Pro.}{:}}%
\newtheorem{example}[TheoremElement]{\insertbehindnumber{Exm.}{:}}%
\renewcommand\theequation{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{equation}}%
\renewcommand\thetable{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{table}}%
\renewcommand\thefigure{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{figure}}%
\renewcommand\thesection{\protect\S\texorpdfstring{\protect\,}{ }\arabic{section}}%
\AtBeginDocument{%
  % Remove the dot after chapter-numbers in headers of verso pages:
  %\renewcommand*\chaptermark[1]{%
  %  \markboth{%
  %    \MakeUppercase{%
  %      \ifnum\c@secnumdepth>\m@ne\if@mainmatter\@chapapp\ \thechapter\quad\fi\fi#1%
  %    }%
  %  }{}%
  %}%
  % Remove the dot after sectioning-paragraph-numbers in headers of recto pages:
  \renewcommand*\sectionmark[1]{%
     \markright{%
       \MakeUppercase{\ifnum\c@secnumdepth>\z@\thesection\quad\fi#1}%
     }%
  }%
  \@ifpackageloaded{hyperref}{%
    % Ensure uniqueness of hyperref' anchor names:
    \renewcommand\theHsection{\arabic{section}}%
    \renewcommand\theHTheoremElement{\AllSectionLevelsArabic}%
    \renewcommand\theHequation{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{equation}}%
    \renewcommand\theHtable{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{table}}%
    \renewcommand\theHfigure{\sectionfakefork{\arabic{section}.}{\arabic{chapter}/}\arabic{figure}}%
    \renewcommand\theHfootnote{\arabic{chapter}.\arabic{footnote}}%
  }{%
    \providecommand\texorpdfstring[2]{#1}%
  }%
}%
\makeatother

\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{\value{secnumdepth}}
\usepackage[open,openlevel=\value{secnumdepth},atend,numbered]{bookmark}    

\begin{document}
\tableofcontents

\setcounter{chapter}{-1}%

\chapter{Basics}

\begin{definition}
Some definition.
\end{definition}

\section{Sets}

\begin{definition}
\label{deflabel}Some definition.
\end{definition}

\begin{definition}
Some definition.
\end{definition}

\begin{proposition}
\label{proplabel}Some proposition.
\end{proposition}

\begin{example}
\label{exlabel}Some example.
\end{example}

\section{Other section}

\section{Other section}

\begin{definition}
Some definition.
\end{definition}

\begin{definition}
Some definition.
\end{definition}

\begin{proposition}
Some proposition.
\end{proposition}

\begin{example}
Some example.
\end{example}

\section{Other section}

\chapter{Groups, Rings and Fields}

\begin{definition}
\label{otherdeflabel}Some definition.
\end{definition}

\section{Groups}

\begin{definition}
Some definition.
\end{definition}

\subsection{SubGroups}

\begin{definition}
Some definition.
\end{definition}

\subsubsection{SubSubGroups}

\begin{definition}
\label{yetanotherdeflabel}Some definition.
\end{definition}

\section{Rings}

\cleardoublepage
\section{Testing referencing}

referencing a definition: \ref{deflabel}\\
referencing a proposition: \ref{proplabel}\\
referencing an example: \ref{exlabel}\\
referencing another definition: \ref{otherdeflabel}\\
referencing yet another definition: \ref{yetanotherdeflabel}
\end{document}

相关内容