3

Is it possible not to display the last chapter in the second parttoc ?

\documentclass[a4paper,oneside]{scrbook}
\usepackage{minitoc}
\setcounter{tocdepth}{0} 

\begin{document}
\doparttoc
\tableofcontents

\part{Part 1}
\parttoc
\chapter{Chapter 1}
\chapter{Chapter 2}

\part{Part 2}
\parttoc
\chapter{Chapter 3}
\chapter{Chapter 4}

\end{document}
1
  • I tried my luck and got the exact opposite of what you wanted with chapter 4 missing in toc but not in parttoc. I used the tocvsec2 package and with \settocdepth{part} bevor the chapter 4 I got that result, because it changes the depth of the toc at a specific point in a document. So in theory shouldn't it be possible to write a macro doing the exact same thing, but just for parttoc instead of toc? Unfortunately I have no experience with that.
    – Gilean0709
    Commented Aug 19, 2014 at 15:10

2 Answers 2

1

If you don't mind changing the insides of minitoc a little you can do this. I'm not sure this answer is a particularly good one because

  • The minitoc documentation mentions that the package has been substantially reworked at least once, so there's a lot of reason to doubt this solution will work with older versions of the package. (And of course, if future versions change how minitoc's \PTC@test command is used, it might not with those either.)
  • The \skipcontents and \readcontents commands I'm about to define don't quite work as intuitively as I think they ought. (E.g., the caveat at the end of this answer)

Consequently, a better idea may be to just switch and use etoc. If you're absolutely set on minitoc, though, here is a sort-of answer.

Since minitoc reads through the .toc file and picks out relevant commands like \contentsline and puts them in their own partial toc (.ptc) files. You can (sort of) get what you want by redefining the command \PTC@test, which minitoc uses to test for relevance, so that it also tests whether you've told it to ignore \contentslines. You can then add commands to the .toc file which don't do anything, but which minitoc recognizes as switching the relevance of \contentsline on or off.

  \documentclass[a4paper,oneside]{scrbook}
    \usepackage{minitoc}
    \newif\ifignorecontents
    \newcommand\skipcontents{\addtocontents{toc}{\protect\ignorecontentstrue}}
    \newcommand\readcontents{\addtocontents{toc}{\protect\ignorecontentsfalse}}
    \makeatletter
    %Mostly copied from minitoc documentation p.357, ll.4257-4271
    \long\def\PTC@test#1#2#3#4#5#6\PTC@{%  
     \ifx#1\ignorecontentstrue \ignorecontentstrue\else
     \ifx#1\ignorecontentsfalse \ignorecontentsfalse\else
     \ifx#1\contentsline
          \ifignorecontents\else
            \let\mtc@string\string
            \PTC@contentsline{#2}{#3}{#4}{#5}%
            \let\mtc@string\relax
          \fi
     \else\ifx#1\@input
           \edef\PTC@list{\PTC@list#2\relax}%
     \else\ifx#1\partend
            \immediate\closeout\tf@mtc
             \immediate\openout\tf@mtc=\jobname.mtc
     \else\ifx#1\partbegin
              \addtocounter{ptc}{-1}%
     \fi\fi\fi\fi\fi\fi
     \ifeof\@inputcheck\expandafter\PTC@toc
     \else\expandafter\PTC@read\fi}%
    \makeatother
    \begin{document}

And then around the chapter you don't want

    \chapter{Chapter 3}

    \skipcontents %exclude from part's toc

    \chapter{Chapter 4}

    \readcontents %start including again

    \chapter{Chapter 5}

But if you have something like

    \chapter{Chapter 3}
    \section{3.1}
    \section{3.2}
    \skipcontents
    \section{3.3}
    \chapter{Chapter 4} 
    \section{4.1}
    \section{4.2}
    \readcontents
    \section{4.3}

you'll get a line for section 4.3 under chapter 3 in the partial toc.

2

After a look at the minitoc package it is possible to put a bound on the parttoc with \addtocontents{toc}{\protect\partbegin}. Unfortunately this just works for the last chapters of a part, but not for chapters inbetween.

\documentclass[a4paper,oneside]{scrbook}
\usepackage{minitoc}
\setcounter{tocdepth}{0} 

\begin{document}
\doparttoc
\tableofcontents

\part{Part 1}
\parttoc
\chapter{Chapter 1}
\chapter{Chapter 2}

\part{Part 2}

\parttoc
\chapter{Chapter 3}
\addtocontents{toc}{\protect\partbegin}
\chapter{Chapter 4}
\end{document}`

You must log in to answer this question.

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