0

I want to add volume in front of the part level, I've implemented this feature, but there is a warning that I have not been able to dismiss.

The MWE is as follows:

\documentclass{book}
\usepackage{titlesec}
\makeatletter
    \newcounter{volume}
    \setcounter{volume}{0}
    \def\toclevel@volume{-2}
    \renewcommand\thevolume{Vol. \@arabic\c@volume}
    \newcommand\volume{
        \if@openright
            \cleardoublepage
        \else
            \clearpage
        \fi
        \thispagestyle{empty}
        \if@twocolumn
            \onecolumn
            \@tempswatrue
        \else
            \@tempswafalse
        \fi
        \null\vfil
        \secdef\@volume\@svolume}
    \def\@volume[#1]#2{
        \ifnum \c@secnumdepth >-3\relax
            \refstepcounter{volume}
            \addcontentsline{toc}{volume}{\thevolume\hspace{1em}#1}
        \else
            \addcontentsline{toc}{volume}{#1}
        \fi
        \markboth{}{}
        {\centering
        \interlinepenalty \@M
        \normalfont
        \ifnum \c@secnumdepth >-3\relax
            \Huge\bfseries \volumename\nobreakspace\@arabic\c@volume
            \par
            \vskip 20\p@
        \fi
        \Huge \bfseries #2\par}
        \@endvolume}
    \def\@svolume#1{
        {\centering
            \interlinepenalty \@M
            \normalfont
            \Huge \bfseries #1\par}
        \@endvolume}
    \def\@endvolume{\vfil\newpage
        \if@twoside
        \if@openright
            \null
            \thispagestyle{empty}
            \newpage
        \fi
        \fi
        \if@tempswa
            \twocolumn
        \fi}
    \newcommand*\l@volume[2]{
        \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}
    \newcommand\volumename{Volume}
\makeatother

\usepackage{titletoc}
\setlength{\titlewidth}{0.5\textwidth}
\titlecontents{volume}
    [0pc]
    {\addvspace{1pc}\bfseries\large\titlerule\addvspace{.3pc}\centering}
    {}
    {}
    {\enspace \contentspage}
    [\addvspace{.3pc}\titlerule]

\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=red}
\makeatletter
    \@addtoreset{part}{volume}
    \@addtoreset{chapter}{volume}
\makeatother

\title{MWE}
\begin{document}
    \tableofcontents

    \volume{Volume.1}
    \part{Part.1.1}
    \chapter{Chap.1.1.1}
    \chapter{Chap.1.1.2}
    \part{Part.1.2}
    \chapter{Chap.1.2.1}
    \chapter{Chap.1.2.2}

    \volume{Volume.2}
    \part{Part.2.1}
    \chapter{Chap.2.1.1}
    \chapter{Chap.2.1.2}
\end{document}

A warning appears after compilation:

Package titletoc: Unknown TOC type volume. I'll set it for you with
(titletoc)  level -1000..

If you comment out the following sections, the warning disappears.

\titlecontents{volume}
    [0pc]
    {\addvspace{1pc}\bfseries\large\titlerule\addvspace{.3pc}\centering}
    {}
    {}
    {\enspace \contentspage}
    [\addvspace{.3pc}\titlerule]

Is there a way to implement functionality while eliminating warnings? enter image description here

1 Answer 1

1

You mixing two different methods the facilities provided by titlesec and titletoc and those of LaTeX2e and the standard classes. You used the latter. That is why when you remove the lines you mentioned it works :) Do not mix the two methods. Use the facilities of the standard classes + LaTeX2e IMHO is always a better approach.

\documentclass{book}

\makeatletter
\newcounter{volume}
\setcounter{volume}{0}
\def\toclevel@volume{-2}
\newcommand\volume{
    \if@openright
    \cleardoublepage
    \else
    \clearpage
    \fi
    \thispagestyle{empty}
    \if@twocolumn
    \onecolumn
    \@tempswatrue
    \else
    \@tempswafalse
    \fi
    \null\vfil
    \secdef\@volume\@svolume}
\def\@volume[#1]#2{
    \ifnum \c@secnumdepth >-3\relax
    \refstepcounter{volume}
    \addcontentsline{toc}{volume}{\thevolume\hspace{1em}#1}
    \else
    \addcontentsline{toc}{volume}{#1}
    \fi
    \markboth{}{}
    {\centering
    \interlinepenalty \@M
    \normalfont
    \ifnum \c@secnumdepth >-3\relax
        \Huge\bfseries \volumename\nobreakspace\@arabic\c@volume
        \par
        \vskip 20\p@
    \fi
    \Huge \bfseries #2\par}
    \@endvolume}
\def\@svolume#1{
    {\centering
        \interlinepenalty \@M
        \normalfont
        \Huge \bfseries #1\par}
    \@endvolume}
\def\@endvolume{\vfil\newpage
    \if@twoside
    \if@openright
        \null
        \thispagestyle{empty}
        \newpage
    \fi
    \fi
    \if@tempswa
    \twocolumn
    \fi}
\newcommand*\l@volume[2]{
    \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}
\newcommand\volumename{Volume}

\usepackage{hyperref}
\begin{document}
    \tableofcontents
    \volume{Vol.1}
    \part{Part.1}
    \chapter{chap.1}
    \chapter{chap.2}
    \volume{Vol.2}
    \part{Part.2}
    \chapter{chap.3}
    \chapter{chap.4}
\end{document}
2
  • Sorry, I don't understand what you mean. If I cancel the use of titlesec on the basis of the original code, it will not compile properly. It would be nice if you could attach your modified code that compiled normally.
    – Chänzz
    Commented Oct 5 at 9:43
  • @Chänzz see my edit
    – yannisl
    Commented Oct 5 at 10:50

You must log in to answer this question.

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