新的 titleclass 不计入目录

新的 titleclass 不计入目录

下面定义了一个新的titleclass,我不希望它被算入定义的目录中。如何实现呢?

\documentclass{book}
\usepackage{titlesec} 
\usepackage{titletoc}

\titleformat{\chapter}[display]
      {\bfseries\Large}
      {\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
      {1ex}
      {\titlerule\vspace{1ex}\filleft}
      [\vspace{1ex}\titlerule]

\titleclass{\sample}{straight}[\chapter]
\newcounter{sample}
\renewcommand{\thesample}{\arabic{sample}}

\titlespacing*{\sample}{0pt}{3.5ex plus 1ex minus .2ex}{1ex plus .2ex}

\titleformat{\sample}[block]
{\titlerule*[.6em]{\bfseries.}\normalfont\sffamily\Large\leavevmode\\[-11pt]}
{\bfseries\Large Sample \thechapter.\thesample}
{0pt}
{\enspace\bfseries}
[]

\begin{document}
    \chapter{Test Unnumbered Chapter}
    \startcontents[chapters]%
    \printcontents[chapters]{}{1}{}
    \sample{ex1}
    \sample{ex2}
    \chapter{Test Numbered Chapter}
\end{document}

在此处输入图片描述

答案1

提供(可能\titlecontents为空)sample并在以下所需级别启动部分 ToC sample

\documentclass{book}
\usepackage{titlesec} 
\usepackage{titletoc}

\titleformat{\chapter}[display]
      {\bfseries\Large}
      {\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
      {1ex}
      {\titlerule\vspace{1ex}\filleft}
      [\vspace{1ex}\titlerule]

\titleclass{\sample}{straight}[\chapter]
\newcounter{sample}
\renewcommand{\thesample}{\thechapter.\arabic{sample}}

\titlespacing*{\sample}{0pt}{3.5ex plus 1ex minus .2ex}{1ex plus .2ex}

\titleformat{\sample}[block]
{\titlerule*[.6em]{\bfseries.}\normalfont\sffamily\Large\leavevmode\\[-11pt]}
{\bfseries\Large Sample \thesample}
{0pt}
{\enspace\bfseries}
[]

\titlecontents{sample}
  {}{}{}{}

\begin{document}
    \startcontents[chapters]%
    \chapter{Test Unnumbered Chapter}
    \printcontents[chapters]{}{2}{}
    \section{Test Section}
    \sample{ex1}
    \sample{ex2}
    \chapter{Test Numbered Chapter}
\end{document}

在此处输入图片描述

相关内容