9
\documentclass{mwrep}    
\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\chapter*{c4}
\section*{s}
\chapter{c5}
\end{document}

I know chapter* removes a chapter from numbering. How can I remove it also from ToC? I want to remove c4 but not c3.

Ichibann
  • 8,381

1 Answers1

12

To remove from the ToC all the entries associated with \chapter* you need to redefine the \chapter@toc command implemented in mwrep.cls; the following example code includes the necessary redefinition:

\documentclass{mwrep} 

\makeatletter
\renewcommand*\chapter@toc{%
  \ifHeadingNumbered\typeout{\@chapapp\space\thechapter.}
  \addcontentsline{toc}{chapter}{%
        \ifHeadingNumbered
 \protect\numberline{\mw@seccntformat{\HeadingNumber}}%
        \fi
            \HeadingTOCText}\fi%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  }
\makeatother

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\end{document}

To remove from the ToC only a particular entry associated with \chapter* you could 1) use the tocvsec2 package:

\documentclass{mwrep} 
\usepackage{tocvsec2}

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\settocdepth{part}
\chapter*{c4}
\settocdepth{section}
\end{document}

or 2) Use \addtocontents to appropriately change the value of the tocdepth counter:

\documentclass{mwrep} 

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\addtocontents{toc}{\setcounter{tocdepth}{-1}}
\chapter*{c4}
\addtocontents{toc}{\setcounter{tocdepth}{2}}
\end{document}
Gonzalo Medina
  • 505,128
  • And this makes every chapter* excluded? This is not what I want. I corrected my question because it was misleading. – Ichibann Jul 27 '11 at 22:49
  • @Ichibann: Yes. I've updated my answer to provide a solution for the new requirement. – Gonzalo Medina Jul 27 '11 at 23:00
  • Your secont way does not work (in example as in my edited question). First works without problems. – Ichibann Jul 27 '11 at 23:54
  • @Ichibann: what exactly doesn't work? In your new edit what do you want to remove from the ToC? – Gonzalo Medina Jul 28 '11 at 00:28
  • @GonzaloMedina Solution 2) makes the ToC disappear completely. Solution 1) works great. – stanwise Sep 13 '12 at 15:23
  • @stanwise Can you please please provide some code illustrating your affirmation about Solution 1)? – Gonzalo Medina Sep 13 '12 at 15:27
  • @GonzaloMedina What do you mean by providing code? It worked in my MSc thesis, which I will not quote here, as it's too long. And you already provided syntetic code for solution 1, which works for me. – stanwise Sep 15 '12 at 20:36
  • @stanwise my bad. I meant, solution 2) (the one you said didn't work for you). By providing code, I mean a minimal, but complete document allowing me to reproduce the problem mentioned; obviously, this minimal document doesn't have to include any "real" content; there are a number of ways of obtaining filler text (if required). – Gonzalo Medina Sep 15 '12 at 20:39
  • @GonzaloMedina: Well, with solution 2 it is quite similar. It didn't work on my thesis. It also doesn't work with syntetic example that you provided. At least on my LaTeX installation (MikTeX 2.9). – stanwise Sep 15 '12 at 20:44
  • @stanwise that's what I don't understand; the code I posted works as expected, so if it's not working for you, then you probably have other settings in your document. Or do you mean that the exact code I posted is not working for you? – Gonzalo Medina Sep 15 '12 at 20:49
  • @GonzaloMedina: My mistake. I thought your exact code didn't work, but forgot to compile twice. After second compilation your exact code works as intended. However in my thesis I still get empty ToC. So I think that there may be some package conflicts that prevent this from working with my thesis. What is interesting is that when I accidentaly left \usepackage{tocvsec2} from solution 1, solution 2 worked. Unfotunately I don't have time to check every single package or setting dependency right now, so I'll stick to solution 2. – stanwise Sep 15 '12 at 21:06
  • If you want to fiddle with it here is my main.tex: http://pastebin.com/fJqQt8VN In included files there are simply \chapters defined. In MyPublications there is \chapter* defined – stanwise Sep 15 '12 at 21:21
  • @GonzaloMedina, This only redefines \chapter*{} -- \section*{}still appears in the TOC, which is weird. –  Jun 22 '16 at 17:10