![如何在部分级别创建自定义“...列表”?](https://linux22.com/image/235088/%E5%A6%82%E4%BD%95%E5%9C%A8%E9%83%A8%E5%88%86%E7%BA%A7%E5%88%AB%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E2%80%9C...%E5%88%97%E8%A1%A8%E2%80%9D%EF%BC%9F.png)
答案1
参见包中的“7.4.部分列表” titletoc
,它可能就是您想要的。
我猜也许minitoc
这个问题本身也能解决。但我不确定。
对于用户定义的浮点数,我只能破解titletoc
。幸运的是,这并不难。我认为应该将此功能添加到中titletoc
。
\documentclass{article}
\usepackage{float,titletoc}
\newfloat{myflt}{htbp}{mine}
\makeatletter
\def\ttl@partialmine{pmine}
\def\ttl@writepartial#1#2{%
\ttl@topartial{toc}{#1}{#2}%
\ttl@topartial{lof}{#1}{#2}%
\ttl@topartial{lot}{#1}{#2}%
\ttl@topartial{mine}{#1}{#2}%
\ttl@writefile{#1}{#2}}
\makeatother
\newcommand{\listofmyflt}{\listof{myflt}{Full list}}
\newcommand{\partiallistofmyflt}{
\startlist{mine}%
\printlist{mine}{}{\subsection*{Partial list}}}
\begin{document}
\listofmyflt
\section{foo}
\partiallistofmyflt
\begin{myflt}\caption{foo}\end{myflt}
\section{bar}
\partiallistofmyflt
\begin{myflt}\caption{bar}\end{myflt}
\begin{myflt}\caption{baz}\end{myflt}
\stoplist{mine}
\end{document}
答案2
我在下面提供了一个版本,说明如何在非浮动环境中实现这一点。它将写入文件 \jobname.prb;有些人可能认为这是一个缺点,因为它使用了 TeX 的一个写入寄存器。它需要 2 次编译(与任何其他基于 toc 的命令一样)。我欢迎任何反馈。
\documentclass{article}
\usepackage{ifthen}
\usepackage{hyperref}
\usepackage{xstring}
\newcounter{probSectCounter}
\setcounter{probSectCounter}{-1}
\newcounter{echo}
% renew the section command so that it writes
% to the \jobname.prb file
\let\oldsection\section
\renewcommand\section{%
\stepcounter{probSectCounter}%
\addcontentsline{prb}{section}{heading\theprobSectCounter}%
\oldsection}
% custom environment- whatever you want
\newcounter{problem}
\newenvironment{problem}{%
\refstepcounter{problem}%
\textbf{Problem \theproblem }\par%
\addcontentsline{prb}{subsection}{\theproblem}%
}%
{%
\par\vspace{\belowdisplayskip}\noindent\ignorespacesafterend%
}
% define the \listproblems command
\newread\File
\def\listproblems{%
% open the appropriate file do everything in a
% new environment so that we can renew the
% \contentsline command locally
\begin{problemlist}
\openin\File=\jobname.prb%
\loop\unless\ifeof\File%
\read\File to\fileline%
\fileline%
\repeat%
\closein\File%
\end{problemlist}
}%
\makeatletter
% need a command to bring the \contentsline
% into the problemlist environment
\let\orig@contents\contentsline%
\newenvironment{problemlist}%
{%
% renew the \contentsline command locally in this environment
%
% if we renewed the command outside of the environment, it would
% affect \tableofcontents, \minitoc, and perhaps more- bad!
\let\contentsline\orig@contents%
\let\Contentsline\contentsline%
\renewcommand\contentsline[4]{%
\StrCount{##2}{heading}[\heading]%
\ifthenelse{\heading>0}%
{%
\StrCount{##2}{heading\theprobSectCounter}[\heading]%
\ifthenelse{\heading>0}%
{%
\setcounter{echo}{1}%
}%
{%
\setcounter{echo}{0}%
}%
% the command is empty
}%
{%
\ifthenelse{\equal{\theecho}{1}}%
{%
\Contentsline{##1}{##2}{##3}{##4}%
}%
{}%
}%
}%
}%
{}
% enable the \jobname.prb file
\def\prb@enablelistofproblems{%
\begingroup%
\makeatletter%
\if@filesw%
\expandafter\newwrite\csname tf@prb\endcsname%
\immediate\openout \csname tf@prb\endcsname \jobname.prb\relax%
\fi%
\@nobreakfalse%
\endgroup}%
% enable the \jobname.prb files at the end
% of the document
\AtEndDocument{\prb@enablelistofproblems}
\makeatother
\begin{document}
\section{intro}
Welcome to this section.
\listproblems
\begin{problem}
In environment
\end{problem}
\begin{problem}
In environment
\end{problem}
\section{another section}
\listproblems
\begin{problem}
In environment
\end{problem}
\begin{problem}
In environment
\end{problem}
\begin{problem}
In environment
\end{problem}
\end{document}