4

MWE:

Consider the following MWE, which defines a new environment specialChapterEnvironment which I want to use to define properties for 'special' chapter headings. As an example, this is just changing the numeration from arabic to roman letters.

\documentclass{book}


% Defines a new environment for special chapters
\newenvironment{specialChapterEnvironment}{
  \renewcommand{\thechapter}{\Roman{chapter}}
  }{}
  
\begin{document}
\tableofcontents

\setcounter{chapter}{0}
\begin{specialChapterEnvironment}
 \chapter{A special chapter}
\end{specialChapterEnvironment}

\chapter{A normal chapter}
\chapter{Another normal chapter}

\begin{specialChapterEnvironment}
 \chapter{Another special chapter}
\end{specialChapterEnvironment}


\end{document}

Output from the MWE

The output of the code is the following:

enter image description here

Desired Output/Solution

As one would expect the chapter counter increases regardless of the type of the chapter (i.e. normal or special). However, what I would like to have is two independent chapter counters for 'normal' and 'special' chapters, i.e. special chapters should be enumerates as I, II, III... and normal chapters with 1, 2, 3...

What is the easiest way to do this?

4
  • Are you open to using a different class?
    – campa
    Aug 17, 2022 at 8:38
  • Hi @campa, unfortunately I can't change the class of the document.
    – Mark
    Aug 17, 2022 at 8:42
  • define a \specialchapter command by copying the relevant code from book.cls and using a new counter \specialchapter. Aug 17, 2022 at 8:59
  • @UlrikeFischer Would you mind elaborating in an answer? Is there really no simpler solution?
    – Mark
    Aug 17, 2022 at 9:27

2 Answers 2

3

You can locally redefine \c@chapter (the internal name of the chapter counter) to \c@specialchapter, where specialchapter is the counter for the special chapters.

In the code below oneside and geometry are used just to make a smaller picture. I added hyperref to see that the setting is compatible with it. If you don't plan to use it, remove the line about \theHchapter.

\documentclass[oneside]{book}

\usepackage[a6paper]{geometry}

\usepackage{hyperref}

\makeatletter
\newcounter{specialchapter}
% Defines a new environment for special chapters
\newenvironment{specialChapterEnvironment}
 {%
  \let\c@chapter\c@specialchapter
  \renewcommand{\thechapter}{\Roman{chapter}}%
  \renewcommand{\theHchapter}{\Roman{chapter}}%
  % add here other settings
 }
 {}
\makeatother

\begin{document}

\tableofcontents

\begin{specialChapterEnvironment}
 \chapter{A special chapter}\label{one}

\ref{one} \ref{two} \ref{three} \ref{four}
\end{specialChapterEnvironment}

\chapter{A normal chapter}\label{two}
\chapter{Another normal chapter}\label{three}

\begin{specialChapterEnvironment}
 \chapter{Another special chapter}\label{four}
\end{specialChapterEnvironment}

\end{document}

enter image description here

4
  • This is great, many thanks! Maybe a quick follow-up question: is there a simple way to make the 'special' chapter headings in the table of contents appear larger than the normal chapters? (the actual heading size can remain identical)
    – Mark
    Aug 17, 2022 at 11:36
  • 1
    you could add \renewcommand\Hy@chapapp{specialchapter} if you want \autoref to be able to distinguish both types. Aug 17, 2022 at 11:52
  • @Mark Aren't you looking for \part?
    – egreg
    Aug 17, 2022 at 12:37
  • @egreg I did look into part, but I do not want to have a single page with the heading and then a page break, so I figured it would be easier to just change the Chapter behaviour. So now the only really thin missing is to get the special Chapter headings in the ToC slightly larger.
    – Mark
    Aug 17, 2022 at 12:46
1
\documentclass{book}

\makeatletter
\newcounter{specialchapter}
\renewcommand\thespecialchapter{\Roman{specialchapter}}
\newcommand\specialchapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@specialchapter\@schapter}
\def\@specialchapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{specialchapter}%
                         \typeout{\@chapapp\space\thespecialchapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thespecialchapter}#1}%
                       \else
                         \addcontentsline{toc}{chapter}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makespecialchapterhead{#2}]%
                    \else
                      \@makespecialchapterhead{#2}%
                      \@afterheading
                    \fi}
\def\@makespecialchapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thespecialchapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}                    
\makeatother

%for section etc thechapter must be changed
\AddToHook{cmd/specialchapter/before}{\let\thechapter\thespecialchapter}
\AddToHook{cmd/chapter/before}{\renewcommand\thechapter{\arabic{chapter}}}

\begin{document}
\tableofcontents

\specialchapter{A special chapter}
\section{special}
\chapter{A normal chapter}
\section{normal}
\chapter{Another normal chapter}
\section{normal}
\specialchapter{Another special chapter}

\end{document}

enter image description here

You must log in to answer this question.

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