1

I want chapter numbers prefixed by a letter like

M1: First chapter of "M" series
M1.1 First section in first chapter of "M" series
M2: Second chapter of "M" series
...

then change the prefix, e.g. to R

R1: First chapter of "R" series
R2: Second chapter of "R" series
...

I tried with some suggestions in scrguide like chapterlinesformat, but either the numbering did not work at all or was not resembled in the toc.

The TOC should look like

M1 chapterName1.................1
   M1.1 sectionname.............3
M2 chapterName..................5
R1 chapterName..................8
   R1.1 sectionname............10

etc.

Any suggestions are welcome

Sorry for not giving a MWE, since it is NOT working. one of my attemps follows: %Minimum NOT working example

\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}
4
  • 2
    I have a suggestion for you: Being a member for more than 2 years should result in a MWE, not only a vague description
    – user31729
    Commented Nov 29, 2017 at 18:13
  • In my opinion you should change \thechapter here rather
    – user31729
    Commented Nov 29, 2017 at 19:13
  • How exactly shall I change that?In the "big" LaTeX document every chaper is in its own file, starting with \chapter{}. My attempt is to leave all the chaper files "as is" and make any changes only to the file where I \input{} the chapters. Commented Nov 29, 2017 at 19:17
  • 2
    Can you please have look on your other questions. There were some answers to them. Maybe you can accept of them if the have solved your issues.
    – esdd
    Commented Nov 29, 2017 at 19:47

2 Answers 2

1

Edit: I have stolen the idea by Christian Hupfer to redefine \thechapter and added the formatting of the TOC using the KOMA-Script-specific command \DeclareTOCStyleEntry. The command \chapterformat does not need to be changed in this case.

\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}

This is how the TOC looks like:

TOC

I did not bother to deal with chapter prefixes available in KOMA-Script; they could be added as needed. Furthermore, I removed the document class options that are set by default in order to simplify the MWE.

2
  • I can confirm this. Now the question is how to get the correct TOC. Commented Nov 29, 2017 at 19:32
  • @HermannGebhard Please see my edit.
    – Matthias
    Commented Nov 29, 2017 at 19:45
3

It seems that the chapter counter is resetted each time when the prefix is changed. So the prefix should be part of the chapter number.

Additionally you have to adjust tocnumwidth and tocindent for all section levels in TOC.

\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}

Result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .