删除 minitoc 中的前缀数字

删除 minitoc 中的前缀数字

我想在 minitoc 打印中省略章节号。例如,在下面的 mwe 中,我希望第二章的 minitoc 打印“1 Test 1”而不是“2.1 Test 1”。

\documentclass{book}
\usepackage{minitoc}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}

答案1

文件中的每个条目都mtcX采用以下形式

{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.1}Test 1}{\reset@font\mtcSfont 3}}

其中\mtc@string定义为\relax。我们可以重载它来(局部)修改 的含义,\numberline以吞噬并包括第一个句点。

\documentclass{book}
\usepackage{minitoc}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\makeatletter
\let\xumtc@numberline\numberline
\protected\def\mtc@string{\let\numberline\xumtc@gobble@numberline}
\def\xumtc@gobble@numberline#1{\xumtc@gobble@@numberline#1\@nil}
\def\xumtc@gobble@@numberline#1.#2\@nil{\xumtc@numberline{#2}}
\makeatother

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}

在此处输入图片描述

更高级别的补丁可以解决可能缺少的句号问题(\numberline{}尽管如此,我们可能需要解决 minitoc 中包含的未编号部分的问题):

\documentclass{book}
\usepackage{minitoc}
\usepackage{expl3}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\ExplSyntaxOn
\cs_new_protected:Nn \xumtc_string:
 {
  % locally change \numberline to gobble up to and including the first period
  \cs_set_eq:NN \numberline \xumtc_gobble_numberline:n
 }
% the 'external' name
\cs_set_eq:cN { mtc@string } \xumtc_string:
% save the old meaning of \numberline
\cs_set_eq:NN \xumtc_numberline:n \numberline
% define a variant that first expands the argument
\cs_generate_variant:Nn \xumtc_numberline:n { x }
% allocate a variable
\seq_new:N \l__xumtc_numberline_seq
% the main macro
\cs_new_protected:Nn \xumtc_gobble_numberline:n
 {
  % split the argument at periods
  \seq_set_split:Nnn \l__xumtc_numberline_seq { . } { #1 }
  % discard the first item
  \seq_pop_left:NN \l__xumtc_numberline_seq \l_tmpa_tl
  % yield the remaining items with a period between them
  \xumtc_numberline:x { \seq_use:Nn \l__xumtc_numberline_seq { . } }
 }
\ExplSyntaxOff

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}

相关内容