4

I am using memoir which currently supports book, part, chapter, section, subsection, etc... I would like an additional layer above this (say "volume") which behaves well (numbered and appears in a table of contents).

I have come across this question More section headings? which helps produce levels below the default ones but I am struggling to reverse this procedure.

  • 1
    You have at least two options: Copy whatever is involved with \book over into a new macro called \volume, or create \volume from scratch. Since you don't present any details in terms of the look/feel/interaction of \volume compared to the rest of the document, at best an answer would most likely copy \book into \volume. It's still a lot of work though... – Werner Nov 15 '14 at 1:54
5

From the memoir basic user manual (section 6.2 SECTIONAL DIVISIONS, p 74):

A \section command restarts the numbering of any \subsections from one. For most of the divisions the <title> is put on the page where the command was issued. The \book, \part and \chapter commands behave a little differently.

The \book and \part commands are simpler and both behave in the same way. The \book{<title>} command puts the book name (default Book), number and <title> on a page by itself. The numbering of books has no effect on the numbering of \parts or \chapters.

We can make an entire copy of \book, and call it \volume, and it'll react in the same way:

enter image description here

\documentclass{memoir}
\setcounter{tocdepth}{5}% Just for this example
\setcounter{secnumdepth}{5}% Just for this example

\makeatletter
\newcounter{volume} \setcounter{volume}{0}
\renewcommand*{\thevolume}{\@Roman\c@volume}
\newcommand*{\theHvolume}{\arabic{volume}}
\newcommand*{\toclevel@volume}{-3}
\newcommand*{\volume}{%
  \@setupvolume
  \secdef\@volume\@svolume}
\newcommand*{\beforevolumeskip}{\null\vfil}
\newcommand*{\midvolumeskip}{\par\vskip 2\onelineskip}
\newcommand*{\aftervolumeskip}{\vfil\newpage}
\newcommand{\@setupvolume}{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{volume}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \beforevolumeskip}
\newcommand*{\volumename}{Volume}
\newcommand*{\volumenamefont}{\normalfont\huge\bfseries}
\newcommand*{\volumenumfont}{\normalfont\huge\bfseries}
\newcommand*{\volumetitlefont}{\normalfont\Huge\bfseries}
\newcommand*{\printvolumename}{\volumenamefont \volumename}
\newcommand*{\volumenamenum}{\space}
\newcommand*{\printvolumenum}{\volumenumfont \thevolume}
\newcommand*{\printvolumetitle}[1]{\volumetitlefont #1}
\newcommand{\memvolumeinfo}[3]{}
\newcommand{\memvolumestarinfo}[1]{}
\long\def\@volume[#1]#2{%
  \M@gettitle{#1}%
  \def\f@rtoc{#1}%
  \@nameuse{volume@f@rtoc@before@write@hook}%
  \phantomsection
  \mempreaddvolumetotochook
  \ifnum \c@secnumdepth >-4\relax
    \refstepcounter{volume}%
    \addcontentsline{toc}{volume}%
      {\protect\volumenumberline{\thevolume}\f@rtoc}%
    \memvolumeinfo{\thevolume}{\f@rtoc}{#2}%
  \else
    \addcontentsline{toc}{volume}{\f@rtoc}%
    \memvolumeinfo{}{\f@rtoc}{#2}%
  \fi
  \mempostaddvolumetotochook
  \volumepagemark{#1}%
  {\centering
   \interlinepenalty \@M
   \parskip\z@
   \normalfont
   \ifnum \c@secnumdepth >-4\relax
     \printvolumename \volumenamenum \printvolumenum
     \midvolumeskip
   \fi
   \printvolumetitle{#2}\par}%
  \@endvolume}
\newcommand\mempreaddvolumetotochook{}
\newcommand\mempostaddvolumetotochook{}
\long\def\@svolume#1{%
  \M@gettitle{#1}%
  \phantomsection
  \memvolumestarinfo{#1}%
  {\centering
   \interlinepenalty \@M
   \parskip\z@
   \normalfont
   \printvolumetitle{#1}\par}%
  \@endvolume}
\newif\ifm@mnovolumenewpage
  \m@mnovolumenewpagefalse
\newcommand*{\volumeblankpage}{\m@mnovolumenewpagefalse}
\newcommand*{\novolumeblankpage}{\m@mnovolumenewpagetrue}
\newcommand*{\volumepageend}{\aftervolumeskip
  \ifm@mnovolumenewpage
  \else
    \if@twoside
      \if@openright
        \null
        \thispagestyle{aftervolume}%
        \newpage
      \fi
    \fi
  \fi
  \if@tempswa
    \twocolumn
  \fi}
\def\@endvolume{\volumepageend}
\aliaspagestyle{volume}{empty}
\aliaspagestyle{aftervolume}{empty}
\newcommand*{\cftvolumebreak}{\addpenalty{-\@highpenalty}%
  \addvspace{\cftbeforevolumeskip}}
\newcommand*{\l@volume}[2]{%
  \ifnum\c@tocdepth >-4\relax
    \cftvolumebreak
    \begingroup
      {%
       \memRTLleftskip \cftvolumeindent\relax
       \memRTLrightskip \@tocrmarg
       \parfillskip -\memRTLrightskip
       \parindent \cftvolumeindent\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \settowidth{\@tempdima}{\cftvolumefont\cftvolumename}%
       \addtolength{\@tempdima}{\cftvolumenumwidth}%
       \let\@cftbsnum \cftvolumepresnum
       \let\@cftasnum \cftvolumeaftersnum
       \let\@cftasnumb \cftvolumeaftersnumb
       \advance\memRTLleftskip \@tempdima \null\nobreak\hskip -\memRTLleftskip
       {\cftvolumefont {#1}}%
       \cftvolumefillnum{#2}}
      \nobreak
      \global\@nobreaktrue
      \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\newcommand*\volumenumberlinehook[1]{}
\newcommand{\volumenumberline}[1]{%
  \volumenumberlinehook{#1}%
  \volumenumberlinebox\@tempdima{%
    \cftvolumename\@cftbsnum #1\@cftasnum}\@cftasnumb}%%\space}
\newcommand*{\cftvolumename}{}
\newcommand*{\volumepagemark}[1]{}
\let\volumenumberlinebox\mem@cft@hb@xt@
\newlength{\cftbeforevolumeskip}
  \setlength{\cftbeforevolumeskip}{2.25em \@plus\p@}
\newdimen\cftvolumeindent
  \setlength{\cftvolumeindent}{0em}
\newdimen\cftvolumenumwidth
  \setlength{\cftvolumenumwidth}{1.5em}
\newcommand*{\cftvolumefont}{\large\bfseries}
\newcommand*{\cftvolumepresnum}{}
\newcommand*{\cftvolumeaftersnum}{}
\newcommand*{\cftvolumeaftersnumb}{}
\newcommand*{\cftvolumeleader}{%
  \large\bfseries\cftdotfill{\cftvolumedotsep}}
\newcommand*{\cftvolumedotsep}{\cftnodots}
\newcommand*{\cftvolumepagefont}{\large\bfseries}
\newcommand{\cftvolumeafterpnum}{}
\newcommand{\cftvolumefillnum}[1]{%
  {\cftvolumeleader}%
  \cftvolumeformatpnum{#1}%
  \cftvolumeafterpnum\par}
\newcommand{\cftvolumeformatpnumhook}[1]{}
\newcommand{\cftvolumeformatpnum}[1]{%
  \cftvolumeformatpnumhook{#1}%
  \hb@xt@\@pnumwidth{\hss {\cftvolumepagefont #1}}}
\makeatother

\begin{document}

\tableofcontents

\volume{A volume}
\book{A book}
\part{A part}
\chapter{A chapter}
\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}
\paragraph{A paragraph}
\subparagraph{A subparagraph}

\end{document}
  • Hi Werner. Thank you very much for your help! I very much appreciate the time you took to help me out on this :) – Luke Nov 15 '14 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.