TransWikia.com

How to insert a page break in a minitoc but not in toc?

TeX - LaTeX Asked by nlair on May 23, 2021

I would like to insert a page break in a minitoc of a chapter between two subsections but I don’t want it in the global toc at the beginning of the document.

Any idea how I could achieve this ?

Here is a MWE :

documentclass{memoir}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{minitoc}

usepackage{xr-hyper}
usepackage{varioref}
usepackage{hyperref}
usepackage{cleveref}

setsecnumdepth{subsection} % numbering of subsection if memoir document
setcounter{tocdepth}{1}
setcounter{minitocdepth}{2}

dominitoc

begin{document}

tableofcontents
adjustmtc

chapter{1}
minitoc

section{1a}
Hello
subsection{1aa}
blabla

% PAGE BREAK HERE%
subsection{1ab}
blabla
section{1b}

end{document}

Solutions I tried

  • addtocontents{toc}{protectpagebreak} but it adds a pagebreak to the toc and not in the minitoc
  • addcontentsline{toc}{subsection}{protectpagebreak} that almost does what I am looking for but adds a line of dot and a page number in the minitoc.
  • cftaddtitleline{toc}{subsection}{protectpagebreak}{} that gets rid of the page number but not the line dots. I could not find how to get rid of the dots for a specific entry…

Thanks for your help !

One Answer

An easy way of managing the ToC entries is to highjack one that you'll probably never use. That way the process behind the scenes remains the same, especially when dealing with minitoc. So, below I take over how starparagraphs (stemming from paragraph*) is handled:

documentclass{memoir}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{minitoc,etoolbox}

usepackage{xr-hyper}
usepackage{varioref}
usepackage{hyperref}
usepackage{cleveref}

setsecnumdepth{subsection} % numbering of subsection if memoir document
setcounter{tocdepth}{1}
setcounter{minitocdepth}{2}

newcommand{addtominicontents}[1]{%
  addcontentsline{toc}{starparagraph}{#1}%
}
newififmaintoc% Used to see whether we're setting tableofcontents or minitoc
AtBeginDocument{%
  letoldtableofcontentstableofcontents
  RenewDocumentCommand{tableofcontents}{ s }{%
    maintoctrue% In the main ToC
    IfBooleanTF{#1}
      {oldtableofcontents*}
      {oldtableofcontents}%
    maintocfalse% Outside of the main ToC
  }%
}
letoldcontentslinecontentsline
renewcommand{contentsline}[4]{%
  ifnumpdfstrcmp{#1}{starparagraph}=0% If we're processing a starparagraph
    ifmaintocelse% In the main ToC, do nothing, otherwise
      #2% Set it as-is
    fi
  else% We're not processing a starparagraph, so execute the regular contentsline process
    oldcontentsline{#1}{#2}{#3}{#4}%
  fi
}

dominitoc

begin{document}

tableofcontents
adjustmtc

chapter{1}
minitoc

section{1a}
Hello
subsection{1aa}
blabla

addtominicontents{protectvfillprotectpagebreak}

subsection{1ab}
blabla
section{1b}

end{document}

The approach is to write whatever you want to the regular (main) ToC under the guise of being a startparagraph. Then, process starparagraph entries in an as-is way, rather than setting them in the usual ToC manner (with a clickable hyperlink, a leader and page number). Since the ToC-related hyperlinking is broken into parts (to capture the destination of the link and set it across the sectional unit title), it's easier to condition at the start of contentsline whether we're dealing with a starparagraph or not. Then, within the true branch, we condition on whether we're in the main ToC or not, just to make sure we completely ignore the entry in the former case, but set it as-is in the latter.

Here is the default (main) ToC:

enter image description here

And here is the mini-ToC for Chapter 1, broken in two:

enter image description here

If you're not running a current/up-to-date LaTeX, you may have to add usepackage{xparse} to your preamble before being able to use RenewDocumentCommand.

Correct answer by Werner on May 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP