代码

代码

最后,我将问题缩小到titlesec显式模式下使用自定义的分段命令。我怀疑这与我没有提供足够的计数器有关etoc

第一次运行编译正常。第二次运行结果如下:

!缺失数字,视为零。\Etoc@level l.27 \section {etoc} ?

代码

\documentclass{article}
\usepackage{fontspec}
%\usepackage{tocloft} % I use this package too.
\usepackage[explicit]{titlesec}
\usepackage{etoc}
%\usepackage{hyperref} % I use this package too.

%\let\tableofcontents\etoctableofcontents %counteract the overwriting by tocloft of \tableofcontents done at  \begin{document} <--Do I need this?

% MINISECTION (Custom)
\titleclass{\minisec}{straight}[\paragraph]
\newcounter{minisec}
\titleformat{\minisec}[hang]{\normalsize\bfseries}{\theminisec}{0pt}{#1}% Change 0pt to a positive value once the representation for the counter has been established
\titlespacing*{\minisec}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\minisecautorefname}{minisec}
\setcounter{secnumdepth}{5}% minisecs will be numebered
\renewcommand\theminisec{}% Provisional empty definition for the counter representation
% Settings for the bookmarks and the ToC entries (change the second
% and third arguments of \@dottedtocline if minisecs should be in the ToC)
\makeatletter
  \def\toclevel@minisec{5}
  \def\l@minisec{\@dottedtocline{5}{3.8em}{3.2em}}
\makeatother

\begin{document}
\localtableofcontents
\section{etoc}
\minisec{Minisec Test}
\end{document}

答案1

你失踪了

\etocsetlevel{minisec}{5}

完整示例;为避免tocloft覆盖的定义\tableofcontents,请使用titles选项。

\documentclass{article}
\usepackage{fontspec}
\usepackage[titles]{tocloft} % I use this package too.
\usepackage[explicit]{titlesec}
\usepackage{etoc}
\usepackage{hyperref} % I use this package too.

% MINISECTION (Custom)
\titleclass{\minisec}{straight}[\paragraph]
\newcounter{minisec}
\titleformat{\minisec}[hang]
  {\normalsize\bfseries}
  {\theminisec}
  {0pt}% Change 0pt to a positive value once the representation for the counter has been established
  {#1}
\titlespacing*{\minisec}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\minisecautorefname}{minisec}
\setcounter{secnumdepth}{5}% minisecs will be numebered
\renewcommand\theminisec{}% Provisional empty definition for the counter representation
% Settings for the bookmarks and the ToC entries (change the second
% and third arguments of \@dottedtocline if minisecs should be in the ToC)
\makeatletter
\def\toclevel@minisec{5}
\etocsetlevel{minisec}{5}  
\def\l@minisec{\@dottedtocline{5}{3.8em}{3.2em}}
\makeatother

\begin{document}
\localtableofcontents
\section{etoc}
\minisec{Minisec Test}
\end{document}

在此处输入图片描述

相关内容