7

I am wondering if it is any possible to create a new sectioning level above \part. I've already scrolled quite a few topics that seem to be related but they didn't really help. Somebody suggested somewhere to push all the levels one step down but (i) this will remove the possibility to use the subparagraph (all right?) and (ii) I am otherwise quite happy with the output I can get with the pre-existing settings and that would be rather troublesome to re-assign every single level (or is there any easy way to do it?).

In short, is it possible to define some sort of \superpart{} with the same settings than \part{} but written bigger or in upper case?

I hope my question was clear enough and I thank you in advance for your answers.

The document structure looks like the following:

\documentclass[a4paper, 10pt]{book}
\usepackage{blindtext}
\renewcommand{\thesection}{\arabic{section}}
\setcounter{secnumdepth}{5}


\begin{document}
\part{This is part1}
\chapter{Chapter title}
\section{This is a section}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\paragraph{Paragraph}
\subparagraph{Subparagraph}

\blindtext

\end{document}
2
  • 1
    Could you please provide an MWE, showing which document class you're using and which titling related packages? The best approach might depend on that. Also, what kind of monster document are you writing that you need everything from \superpart to \subparagraph, and are you sure that any of your readers can actually following such an elaborate sectioning?
    – Skillmon
    Commented May 31, 2021 at 21:59
  • Hello Skillmon. This is indeed a monster document that I want to prepare. To make a long story short, I was originally planning to split it into smaller ones but I figured out that a unique big one would be easier to handle. Anyway. I have edited the original post to add a MWE. Hope this will help to figure out my needs. Commented May 31, 2021 at 22:26

2 Answers 2

18

Sure. There’s no reason you can't go infinitely in any direction.

In book, the section level of \part is -1. You just need to define a level which has level -2.

Dig into book.cls and you'll find the relevant definition of \part:

\newcommand\part{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{plain}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}

\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\def\@spart#1{%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \Huge \bfseries #1\par}%
    \@endpart}
\def\@endpart{\vfil\newpage
              \if@twoside
               \if@openright
                \null
                \thispagestyle{empty}%
                \newpage
               \fi
              \fi
              \if@tempswa
                \twocolumn
              \fi}

Rather than just cut and paste and edit to get our \superpart, let’s have fun and redo the definition with twenty-first-century LaTeX and \NewDocumentCommmand.

The template for a sectioning command in xparse style is¹:

\NewDocumentCommand{\superpart}{s O{#3} m}{%

This says that our command has an optional star-form (s), an optional argument which defaults to the mandatory argument's value and then a mandatory argument.

Then we can do the stuff that \part does to open a new single-column page for the superpart title:

  \if@openright  % ❶
     \cleardoublepage
  \else
     \clearpage
  \fi
  \thispagestyle{plain}%
  \if@twocolumn
     \onecolumn
     \@tempswatrue
  \else
     \@tempswafalse
  \fi % ➀
  \null \vfil % ❷

A few things to note thusfar. On the line I’ve marked ❶, we check to see if we should be on a recto² page and if so we do \cleardoublepage which gets us to the an odd-numbered page. Otherwise, we just start a new page. Also note that we have commands that have @ in them which means that we need to either be in a class/package file or surround our definition with \makeatletter\makeatother.

On the line marked with ❷, the \null before the \vfil is an empty box. Ordinarily, any glue at the top of a page is ignored. This allows us to have our superpart title centered on the page.

Next, we check to see if we’re numbering superparts (we probably are) which depends on both whether the secnumdepth ≥ -2 and also whether we're doing a star form.

We'll explain what the ➀ is about at the bottom of this post.

  \IfBooleanF{#1}{% 
     \ifnum\c@senumdepth > -3\relax
       \refstepcounter{superpart}%
       \addcontentsline{toc}{superpart}{\thesuperpart\hspace{1em}#2}%
     \else
       \addcontentsline{toc}{superpart}{#2}%
     \fi
     \superpartmark{#2}% ❸
  }%

I made a small change to the logic here at ❸ by introducing a new command we’ll define later. book assumes that you don’t want the part name going into headers and doesn’t provide a facility to do so. But maybe you do.

Next we actually print the title.

  {%
     \centering
     \interlinepenalty \@M % ❹
     \normalfamily
     \IfBooleanF{#1}{%
       \ifnum\c@secnumdepth > -3\relax % ❺
         \Huge % ❻
         \bfseries 
         \superpartname\nobreakspace\thesuperpart
         \par
         \vskip 20\p@
       \fi
     }%
  }

The setting at ❹ is misguided and a bad idea, but this is what LaTeX has done for 37 years so I’m not going to change it. It make LaTeX reluctant to break lines within a paragraph. This means that (a) if the title runs longer than a page, the (super)part number will get pushed to the bottom of the page and (2) if the title without the number is still too long to fit on a page, it will just spill over the bottom of the page. Moral of the story don't use long part titles.

I was originally thinking that I should use a temporary switch to avoid repeating the seemingly identical logic at ❺ and the previous code block, but a closer inspection will reveal that the two cases are not exactly identical, thanks to the call to \superpartmark above. Good case for not rushing to optimize early. Plus LaTeX provides @tempswa but not @tempswb.

I hate LaTeX’s size selection commands like the one at ❻. They're a relic of the days of bitmapped fonts locked to Knuth's idiosyncratic choice of powers of 1.2 for type sizes. “Real” typographers would never set something in 17.28pt. The smaller sizes are even worse in that LaTeX uses, e.g., \footnotesize to mean both “two sizes smaller than the normal text size” and also “the formatting for footnotes.” Personally, I think that, at the least, all of the sizing commands should have been private commands with @ in the name.

Finally, we wrap up the superpart page,

  \vfil\newpage
  \if@twoside
     \if@openright
       \null
       \thispagestyle{empty}% ❼
       \newpage
     \fi
  \fi
  \if@tempswa % ❽
     \twocolumn
  \fi
  \@afterheading ❾
}

At ❼, we make sure that if we have an open on recto pages setting, that we insert a blank page without headers or footers. Of course, as we noted above with the setting of \interlineskip, there's no guarantee that our part title actually will be printed on a single page (although there is a guarantee that it will be ugly if it is split across pages).

At ❽ remember way back in the first section when we set \@tempswatrue if we were in two column mode? Now we can take advantage of that by using that value to restore two column mode again.

The command at ❾ is not part of \part, but arguably should be. LaTeX usually suppresses the indent of text after a section heading³ and there's no good reason not to in this context.

Now we have some housekeeping to do. First we declare a counter for our superparts:

\newcounter{superpart}

We would also redefine \thesuperpart if we don't want it to be in arabic numerals which are the default. If you want to use xparse-style definitions, you would need to write, e.g.,

\RenewExpandableDocumentCommand{\thesuperpart}{}{\Roman{superpart}}

If we used \RenewDocumentCommand instead, we would discover that we got the wrong numbers printed in the table of contents and we would be sad. Normally, we want our commands to be robust and not change when they get written to, e.g., a table of contents, but for things like printing a counter value, we want the opposite so that we'll actually get MCMLXXXVIII written instead of \thesuperpart.

If we want parts to be numbered with superparts we would need to also add

\numberwithin{part}{superpart}

For printing the line in the table of contents we need to define \l@superpart. This isn't especially interesting so I've just made small modifications to book’s \l@part:

\NewDocumentCommmand\l@superpart{m}{%
  \ifnum \c@tocdepth >-3\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil
       \hb@xt@\@pnumwidth{\hss #2%
                          \kern-\p@\kern\p@}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}

We will need to define the name that we print for a \superpart. How about being pretentious and calling it “Book”?

\NewDocumentCommand{\superpartname}{}{Book}

And finally, there's the hook that we created for using the superpart title in page headings should we so choose. I decided to have it do what \part does, which is just put empty text into both marks.

\NewDocumentCommand{\superpartmark}{m}{\markboth{}{}}

And that (modulo typos because this is, of course, all untested) is how you can define a sectioning command from scratch.

Edit Ulrike Fischer pointed out that some additional effort is necessary to get the hierarchical bookmarks of hyperref working.⁴ hyperref assumes that we're using the internal macros (and macro structure) of LaTeX to do its work. Here's what it does for \part:

\let\H@old@part\@part % ❿
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname chapter\endcsname\relax
  \let\Hy@secnum@part\z@
\else
  \let\Hy@secnum@part\m@ne
\fi
\def\@part{%
  \ifnum\Hy@secnum@part>\c@secnumdepth
    \phantomsection % ⓫
  \fi
  \H@old@part
}
%    \end{macrocode}
%    \begin{macrocode}
\let\H@old@spart\@spart % ❿
\def\@spart#1{%
  \Hy@MakeCurrentHrefAuto{part*}% ⓬
  \Hy@raisedlink{%
    \hyper@anchorstart{\@currentHref}\hyper@anchorend
  }%
  \H@old@spart{#1}%
}

At ❿ (which occurs twice), we use an old-school trick for patching a macro: \let\foo=\bar (the = is optional) copies the current meaning of \bar into \foo. This is handy when we want to redefine \bar but keep its functionality. For example

\let\foo\bar
\NewDocumentCommand{\bar}{%
   stuff before old bar
   \foo % old bar functionality
   stuff after old bar
}

The kids are all using the patchcmd package or ted to do their changes these days, which is more robust, but either way, these sorts of modifications assume that we know something about the internals of how commands are defined. In any event, hyperref knows nothing about our \superpart command, so it will do nothing.

⓫ is the part that matters for our purposes. \phantomsection adds an anchor at the location where it appears. The documentation indicates that it should be next to \addcontentsline, so we'll have to go back to our documentation and insert \phantomsection after the line that I've marked ➀, except we don't want to just insert this because maybe it doesn't exist! So we'll instead do

\ifdefined\phantomsection
  \phantomsection
\fi

at that point. What about the code at ⓬? Well, it turns out that this is nearly the exact same code as \phantomsection, the only difference being that \phantomsection says \Hy@MakeCurrentHrefAuto{section*} instead of \Hy@MakeCurrentHrefAuto{part*}. The fact that we use \phantomsection in the non-* case indicates that it's not that important what that value is, so we can just have one \phantomsection at the point we chose.

One more thing is necessary for hyperref to handle the hierarchy. We need to have

\NewDocumentCommand{\toclevel@superpart}{}{-2}}

The \toclevel@* commands aren't part of LaTeX’s kernel but are used by, e.g., the ams* classes and hyperref takes advantage of this as well. If we don't have a level defined for a sectioning level, hyperref assumes a default of 0 (equivalent to \chapter in book) which is not what we want. Again, I've tested none of this, but I think I've got all the moving parts in place or at least explained it well enough that you should be able to fix any mistakes.


  1. I'm lying a little bit about this. There is one key difference between this and the default LaTeX definitions of sectioning commands: this definition allows you to write \superpart*[foo]{bar} which would, in default LaTeX be interpreted as \superpart*{[} foo]{bar} where foo]{bar} would be the first paragraph after the \superpart*. (This is mentioned in the xparse documentation, by the way, albeit a bit more tersely.)

  2. Fancy typographer-speak for right hand side. The left side is called verso.

  3. The cases where it does not are after \part and after \chapter in two-column mode. These are, I think, oversights, but 37-years later it's probably too late to change book.cls.

  4. He also caught a few typos which I’ve fixed. Thanks for the proofreading!

4
  • Wow. This is amazing... Thank you very much for the detailed explanations!!! Commented Jun 1, 2021 at 6:30
  • one \NewDocumentCommand has to many m's, secnumdepth is missing the c, \normalpart should probably be \normalfont. If you use hyperref the hierarchy in the bookmarks is not right. Commented Jun 1, 2021 at 8:20
  • @UlrikeFischer feel free to edit for the first free typos if I don’t get to it first. I’ll investigate the hyperref issue later.
    – Don Hosek
    Commented Jun 1, 2021 at 12:16
  • I've edited to include updates per @UlrikeFischer's comment
    – Don Hosek
    Commented Jun 1, 2021 at 14:48
4

The memoir class (a superset of book and report) provides a \book division above the \part division. The manual provides general details about the code for this. Various aspects of the formatting of \book and \part are easily configurable.

You must log in to answer this question.

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