我想要以字母为前缀的章节编号,例如
M1: First chapter of "M" series
M1.1 First section in first chapter of "M" series
M2: Second chapter of "M" series
...
然后更改前缀,例如更改为 R
R1: First chapter of "R" series
R2: Second chapter of "R" series
...
我尝试了 scrguide 中的某些建议,例如 chapterlinesformat,但编号根本不起作用或与目录中的编号不相似。
目录看起来应该是这样的
M1 chapterName1.................1
M1.1 sectionname.............3
M2 chapterName..................5
R1 chapterName..................8
R1.1 sectionname............10
ETC。
欢迎提出任何建议
抱歉,没有给出 MWE,因为它不起作用。我的一次尝试如下:%最低不起作用的示例
\documentclass[
a4paper,
10pt,
pagesize,
titlepage=true,
numbers=noenddot,
]{scrbook}
% deutsches Sprachpaket
\usepackage[ngerman]{babel}
\newcommand{\expprefix}{}
\renewcommand\chapterformat{%
\expprefix\thechapter %\chaptername
\vspace{6pt}%
}
\begin{document}
\tableofcontents
\chapter{This is standard numbering}
% set chapter Prefix to M
\renewcommand{\expprefix}{M}
\setcounter{chapter}{0}
\chapter{This chapter should be numbered M1}
\section{Section1 of first}
\section{Section2 of first}
\chapter{Second chapter of M-series}
%set chapter prefix to R
\renewcommand{\expprefix}{R}
\setcounter{chapter}{0}
\chapter{This chapter should be numbered R1}
\section{Section1 of first R-chapter}
\section{Section2 of first R-chapter}
\chapter{Second chapter of "R" series}
\end{document}
答案1
编辑:我偷了这个想法克里斯蒂安·胡普弗使用 KOMA-Script 特定命令重新定义\thechapter
并添加目录格式。在这种情况下,无需更改\DeclareTOCStyleEntry
命令。\chapterformat
\documentclass[fontsize=10pt, paper=a4, numbers=noenddot]{scrbook}
\usepackage[ngerman]{babel}
\newcommand\expprefix{}
\let\latexorigthechapter\thechapter
\renewcommand{\thechapter}{\expprefix\latexorigthechapter}
\DeclareTOCStyleEntry[numwidth=2.3em]{default}{chapter}
\DeclareTOCStyleEntry[numwidth=3em, indent=2.3em]{default}{section}
\begin{document}
\tableofcontents
\chapter{This is standard numbering}
% set chapter Prefix to M
\renewcommand{\expprefix}{M}
\setcounter{chapter}{0}
\chapter{This chapter should be numbered M1}
\section{Section 1 of first M chapter}
\section{Section 2 of first M chapter}
\chapter{Second chapter of M-series}
% set chapter prefix to R
\renewcommand{\expprefix}{R}
\setcounter{chapter}{0}
\chapter{This chapter should be numbered R1}
\section{Section 1 of first R chapter}
\section{Section 2 of first R chapter}
\chapter{Second chapter of R series}
\end{document}
目录如下所示:
我没有费心处理 KOMA-Script 中可用的章节前缀;可以根据需要添加它们。此外,我删除了默认设置的文档类选项,以简化 MWE。
答案2
每次更改前缀时,章节计数器似乎都会重置。因此前缀应该是章节号的一部分。
tocnumwidth
此外,您还必须调整tocindent
目录中所有章节的级别。
\documentclass[
10pt,
numbers=noenddot,
ngerman
]{scrbook}
\usepackage{babel}
\newcommand*\expprefix{}
\newcommand*\setexpprefix[1]{%
\setcounter{chapter}{0}%
\def\expprefix{#1}%
}
\renewcommand\thechapter{\expprefix\arabic{chapter}}
\RedeclareSectionCommand[
tocnumwidth=2em
]{chapter}
\RedeclareSectionCommand[
tocindent=2em,
tocnumwidth=2.8em
]{section}
\RedeclareSectionCommand[
tocindent=4.8em,
tocnumwidth=4em
]{subsection}
\usepackage{blindtext}% only for dummy text
%\usepackage[naturalnames]{hyperref}
\begin{document}
\tableofcontents
\chapter{This is standard numbering}
\setexpprefix{M}% set chapter Prefix to M
\chapter{This chapter should be numbered M1}
\section{Section1 of first}
\section{Section2 of first}
\chapter{Second chapter of M-series}
\blinddocument \Blindtext[2]
\setexpprefix{R}%set chapter prefix to R
\chapter{This chapter should be numbered R1}
\section{Section1 of first R-chapter}
\section{Section2 of first R-chapter}
\chapter{Second chapter of "R" series}
\end{document}
结果: