1

I can universally vary the table of contents depth.
This is typically handled with command:\setcounter{tocdepth}{ [depth] }.

I can partially vary the table of contents depth.
This is instead handled with package:tocvsec2.

I can create separate tables of contents, such as global and sectional.
This is handled with package:titletoc.

Currently, using tocvsec2 to vary tocdepth affects all titletoc tocs.
I would like separate [partially-varied tocdepth parameters] for separate [tocs].

MWE Explanation

In the MWE,

  • Item 1 has subsections ABC, each with subsubsections xyz.
  • Item 2 has subsections IIa and IIb Each mimics Item 1.
  • Item 3 mimics Item 1.
  • Item 4 has subsections xyz.

What is desired from the MWE,

  • The global table of contents (first) should include Item and ABC sections.
    • This occurs.
  • The global table of contents (first) should exclude xyz subsections.
    • This occurs.
  • Each sectional table of contents (all others) should exclude other top-level sections.
    • This occurs.
  • Each sectional table of contents (all others) should include other subsections.
    • This does not occur.
    • The xyz sections are blocked, like the global section.

The MWE is lengthy. Apologies.

MWE

\documentclass{scrartcl}

\usepackage{geometry}                   % margin/page layout settings
\usepackage{scrlayer-scrpage}           % improved header commands. [supercedes `fancyhdr' package].

\usepackage{titletoc}                   % sub-[tables of contents]
\usepackage[hidelinks]{hyperref}        % hyperlinks.

\usepackage{tocvsec2}                   % variable depth in table of contents


% Margin Settings:
\newlength{\xhmargin   } \setlength{\xhmargin   }{0.750in}
\newlength{\xtmargin   } \setlength{\xtmargin   }{0.750in}
\newlength{\xbmargin   } \setlength{\xbmargin   }{0.750in}
\newlength{\xheadheight} \setlength{\xheadheight}{2.700em}
\newlength{\xheadsep   } \setlength{\xheadsep   }{1.000em}
\newlength{\xfootheight} \setlength{\xfootheight}{2.700em}
\newlength{\xfootskip  } \setlength{\xfootskip  }{3.700em} % [ = Footheight + Footsep]

\KOMAoptions{fontsize   = 12pt         ,
             parskip    = half-        ,
             headheight = \xheadheight , 
             footheight = \xfootheight , 
             DIV        = current      }

\geometry{letterpaper                ,
          hmargin      = \xhmargin   ,
          tmargin      = \xtmargin   ,
          bmargin      = \xbmargin   ,
          headsep      = \xheadsep   ,
          footskip     = \xfootskip  }

%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}


%Setup section numbering: Make \paragraph like \subsubsection.
\makeatletter
\newcommand{\subsubsubsection}{\@startsection{paragraph}{4}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}
\makeatother


%Setup section numbering: Make \paragraph and \subparagraph numbered.
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}   {5}





\begin{document}

\tableofcontents

\clearpage

\settocdepth{subsection}

\section{Item I}

\startcontents[Item I]
\printcontents[Item I]{}{1}{ \subsection*{Contents} }

\clearpage

\subsection{A}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{B}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{C}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\stopcontents[Item I]


\clearpage

\settocdepth{subsubsection}

\section{Item II}

\startcontents[Item II]
\printcontents[Item II]{}{2}{ \subsection*{Contents} }

\clearpage


\subsection{Item IIa}


\clearpage


\subsubsection{A}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{B}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}


\clearpage


\subsection{Item IIb}


\clearpage

\subsubsection{A}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{B}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\stopcontents[Item II]

\clearpage

\settocdepth{subsection}

\section{Item III}

\startcontents[Item III]
\printcontents[Item III]{}{1}{ \subsection*{Contents} }

\clearpage

\subsection{A}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{B}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{C}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\stopcontents[Item III]

\clearpage

\settocdepth{section}

\section{Item IV}

\startcontents[Item IV]
\printcontents[Item IV]{}{1}{ \subsection*{Contents} }

\clearpage

\subsection{x}
\subsection{y}
\subsection{z}

\stopcontents[Item IV]

\end{document}
  • Can a mod please create add the tag for tocvsec2 in this post? I don't have the rep to add it. – kando Aug 26 '15 at 20:43
  • is tocvsec2 necessary? I think titletoc does what you want. – touhami Aug 26 '15 at 20:52
  • 2
    use of titletoc is not recommanded with Koma class – touhami Aug 26 '15 at 20:53
  • @touhami : I don't think so. How so? [I reskimmed the documentation in case I missed something, but I didn't see anything new.] – kando Aug 26 '15 at 21:01
  • 1
    1) what do you mean I don't think so? 2) do you really need koma class? – touhami Aug 26 '15 at 21:17
1

We need to replace

\settocdepth{subsection}

\section{Item I}

\startcontents[Item I]
\printcontents[Item I]{}{1}{ \subsection*{Contents} }

by

\addtocontents{toc}{\string\setcounter{tocdepth}{2}}  %for first table

\startcontents
\section{Item I}

\addtocontents{ptc}{\string\setcounter{tocdepth}{3}}  % for sections tables
\printcontents{}{1}{\subsection*{Contents}}

Note: don't use \stopcontents

Complete code

\documentclass{article}

\usepackage{geometry}
\usepackage{titletoc}                   % sub-[tables of contents]
\usepackage[hidelinks]{hyperref}        % hyperlinks.

\newlength{\xhmargin   } \setlength{\xhmargin   }{0.750in}
\newlength{\xtmargin   } \setlength{\xtmargin   }{0.750in}
\newlength{\xbmargin   } \setlength{\xbmargin   }{0.750in}
\newlength{\xheadheight} \setlength{\xheadheight}{2.700em}
\newlength{\xheadsep   } \setlength{\xheadsep   }{1.000em}
\newlength{\xfootheight} \setlength{\xfootheight}{2.700em}
\newlength{\xfootskip  } \setlength{\xfootskip  }{3.700em} % [ = Footheight + Footsep]


\geometry{letterpaper                ,
          hmargin      = \xhmargin   ,
          tmargin      = \xtmargin   ,
          bmargin      = \xbmargin   ,
          headsep      = \xheadsep   ,
          footskip     = \xfootskip  }



%Setup section numbering: Make \paragraph like \subsubsection.
\makeatletter
\newcommand{\subsubsubsection}{\@startsection{paragraph}{4}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}
\makeatother


%Setup section numbering: Make \paragraph and \subparagraph numbered.
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}   {5}

\begin{document}

\tableofcontents

\clearpage


%--------------------------------
\addtocontents{toc}{\string\setcounter{tocdepth}{2}}

\startcontents
\section{Item I}

\addtocontents{ptc}{\string\setcounter{tocdepth}{3}}
\printcontents{}{1}{\subsection*{Contents}}
%--------------------------------

\clearpage

\subsection{A}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{B}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{C}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}



\clearpage


%--------------------------------
\addtocontents{toc}{\string\setcounter{tocdepth}{3}}

\startcontents
\section{Item II}

\addtocontents{ptc}{\string\setcounter{tocdepth}{4}}
\printcontents{}{1}{\subsection*{Contents}}
%--------------------------------

\clearpage


\subsection{Item IIa}


\clearpage


\subsubsection{A}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{B}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}


\clearpage


\subsection{Item IIb}


\clearpage

\subsubsection{A}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{B}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}

\clearpage

\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}


\clearpage

%--------------------------------
\addtocontents{toc}{\string\setcounter{tocdepth}{2}}

\startcontents
\section{Item III}

\addtocontents{ptc}{\string\setcounter{tocdepth}{3}}
\printcontents{}{1}{\subsection*{Contents}}
%--------------------------------

\clearpage

\subsection{A}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{B}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}

\clearpage

\subsection{C}
\subsubsection{x}
\subsubsection{y}
\subsubsection{z}


\clearpage

%--------------------------------
\addtocontents{toc}{\string\setcounter{tocdepth}{1}}

\startcontents
\section{Item IV}

\addtocontents{ptc}{\string\setcounter{tocdepth}{3}}
\printcontents{}{1}{\subsection*{Contents}}
%--------------------------------

\clearpage

\subsection{x}
\subsection{y}
\subsection{z}


\end{document}
  • Color me impressed. 1: How can you newline in a comment? 2: Why is \string necessary? 3: Why should \stopcontents be avoided? 4: Does using KOMA specifically affect this issue? – kando Aug 27 '15 at 20:00
  • For reference, I tested the code without the \string [2] without issue. I tested the code with \stopcontents [3] and with toc labels, without issue. I tested the code with KOMA [4], without issue. – kando Aug 27 '15 at 20:03
  • NOTE: When using labels for partial tocs, I would avoid spaces despite my MWE. Even when using toc labels, the code to alter depth for a partial toc remains \addtocontents{ptc}{\setcounter{tocdepth}{ [DEPTH] }} regardless of toc label. – kando Aug 27 '15 at 20:08
  • 1
    What I understand: \string not necessary here but it 's good idea for general writing to another file. in my MWE \starcontents will call stopcontents. I am not a KOMA user so I can't tell what is the problem but it is will known that titletoc(sec) break some feature of KOMA class. – touhami Aug 27 '15 at 21:54
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.