目录 [toc]: 使用多个目录时,toc 内的变量 tocdepth

目录 [toc]: 使用多个目录时,toc 内的变量 tocdepth

我可以普遍改变目录深度。
这通常使用命令来处理:\setcounter{tocdepth}{ [depth] }

我可以部分改变目录深度。
这可以通过 package: 来处理tocvsec2

我可以创建单独的目录,例如全局目录和部分目录。
这可以通过 package: 来处理titletoc

目前,使用tocvsec2changetocdepth会影响所有titletoc目录。
我希望tocdepth为单独的 [目录] 设置单独的 [部分变化的参数]。

MWE 解释

在 MWE 中,

  • Item 1有小节ABC,每个小节又有小小节xyz
  • Item 2有小节IIaIIb每个小节都模仿Item 1
  • Item 3模仿Item 1
  • Item 4有 小节xyz

对 MWE 的要求是,

  • 目录global(第一页)应包括ItemABC章节。
    • 发生这种情况。
  • 目录global(第一)应该排除xyz小节。
    • 发生这种情况。
  • 每个sectional目录(所有其他目录)都应排除其他顶级部分。
    • 发生这种情况。
  • 每个sectional目录(所有其他目录)都应包括其他小节。
    • 这不会发生。
    • 这些xyz部分与全局部分一样被阻止。

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}

答案1

我们需要更换

\settocdepth{subsection}

\section{Item I}

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

经过

\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}}

笔记:不要使用\stopcontents

完整代码

\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}

相关内容