无法让 tocloft 的子答案示例发挥作用

无法让 tocloft 的子答案示例发挥作用

代码是从第 15 页上的男人。我正在使用 pdflatex 3.14159265-2.6-1.40.21。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tocloft}

\newlistentry[answer]{subanswer}{1}
\cftsetindents{subanswer}{1.5em}{3.0em} % ERROR: Missing number, treated as zero.
\renewcommand{\thesubanswer}{\theanswer.\alph{subanswer}}
\newcommand{\subanswer}[1]{%
  \refstepcounter{subanswer}\par
  \textbf{\thesubanswer) #1}
  \addcontentsline{ans}{subanswer{\protect\numberline{\thesubanswer}#1}
  }
  \setcounter{ansdepth}{2}
  
\begin{document}

%\answer{Harder} The \ldots\subanswer{Reformulate the problem} It assists \ldots

\end{document}

在此处输入图片描述

答案1

这不是错误的根源。\newlistentry具有以下输入格式:

\newlistentry[<within>]{<entry>}{<ext>}{<level-1>}

您(和tocloft 文档) 没有提供<ext>参数。然后,文档的该部分建立在定义\answer元素的一些先前部分的基础上。

这是一个完整的、最小的编译示例:

\documentclass{article}

\usepackage{tocloft}

\newcommand{\listanswername}{List of Answers}
\newlistof[section]{answer}{ans}{\listanswername}

\newcommand{\answer}[1]{%
  \refstepcounter{answer}\par
  \noindent\textbf{Answer \theanswer. #1}
  \addcontentsline{ans}{answer}{\protect\numberline{\theanswer}#1}\par}

\newlistentry[answer]{subanswer}{ans}{1}
\cftsetindents{subanswer}{1.5em}{3.0em}%
\renewcommand{\thesubanswer}{\theanswer.\alph{subanswer}}
\newcommand{\subanswer}[1]{%
  \refstepcounter{subanswer}\par
  \textbf{\thesubanswer) #1}
  \addcontentsline{ans}{subanswer}{\protect\numberline{\thesubanswer}#1}%
}
\setcounter{ansdepth}{2}
  
\begin{document}

\answer{Harder} The \ldots\subanswer{Reformulate the problem} It assists \ldots

\end{document}

相关内容