创建不是目录的 listofX

创建不是目录的 listofX

我目前用tocloft它来记录我放入摘要页面的建议列表。它非常丑陋,我实际上手动将输出转换为列表以供发布,但它很有用,这样我就可以自动跟踪所有项目。

我想要做的是运行一个计数器,它可以用来构建一个逐项列表。例如:

在此处输入图片描述

我的 MWE 如下所示:

\documentclass[10pt,a4paper]{article}

\newcounter{example}[section]
\newcommand{\example}[1]{%
{\refstepcounter{example}\par\medskip
    \textbf{Example~\theexample. #1} \rmfamily}{\medskip}
}

\begin{document}
    
    \section{summary}
    \subsection{Examples}
    %
    % I would like this list to be generated from a command like \listofExample
    %
    \begin{itemize}
        \item first example
        \item second example
    \end{itemize}
\section{some body text}
Lorizzle ipsum dolor sure amizzle, consectetizzle adipiscing elit. Own yo' sapizzle that's the shizzle, aliquet volutpat, suscipizzle gangsta, gravida dang, owned. Pellentesque crazy tortizzle. Sed erizzle. That's the shizzle at dolor dapibus turpizzle tempizzle break yo neck, yall. Tellivizzle fo shizzle nibh yo yippiyo. Dawg izzle . Sizzle eleifend rhoncizzle bling bling. In hac its fo rizzle platea dictumst. Sheezy go to hizzle. Curabitizzle tellus urna, pretizzle eu, mattis sizzle, eleifend vitae, nunc. Away daahng dawg. Integizzle rizzle hizzle sizzle break yo neck, yall.
    \example{first example}
Dizzle shizznit dolizzle. Fusce magna , dignissizzle sizzle amet, i'm in the shizzle egizzle, sollicitudizzle dizzle, tortor. Boofron hizzle nisi. Cool malesuada neque izzle phat. Suspendisse ma nizzle. Mah nizzle da bomb tristique turpizzle. Suspendisse blandit ultrices purizzle. Sizzle dolor libero, yo interdizzle, posuere ut, dapibizzle izzle, yo mamma. Suspendisse sheezy tellus. Check it out gangsta lectus sizzle gangster dolor. Black dapibizzle gizzle brizzle mofo. Lorem tellivizzle dolizzle crunk amizzle, shiznit adipiscing elizzle. Suspendisse rizzle purus, eleifend laoreet, things id, fo shizzle nizzle, elit. Nizzle mammasay mammasa mamma oo sa rutrizzle dawg.
    \example{second example}
\end{document}

深入研究tocloft源代码看起来...很困难...有人有什么想法吗?

答案1

这是我的草图

\documentclass[10pt,a4paper]{article}

\usepackage[titles]{tocloft}

\newcommand{\listexampletitle}{List of Examples}
\newlistof{examples}{exp}{\listexampletitle}
\newcommand{\examplelist}[1]{%
  \refstepcounter{examples}
  \addcontentsline{exp}{examples}{Example \protect\numberline{\theexamples}#1}
}
\newcommand{\example}[1]{\examplelist{#1}\textbf{Example} \theexamples{}: #1}

\begin{document}
\section{summary}
Lorizzle ipsum dolor sure amizzle...

\listofexamples

\section{some body text}
Lorizzle ipsum dolor sure amizzle...

\example{}
Dizzle shizznit dolizzle...

\example{}
Dizzle shizznit dolizzle...
\end{document}

...和这是我的消息来源。此解决方案涉及使用包tocloft

列表是由标题内的代码生成的,然后您可以将命令\listofexamples及其输出移动到文档中的任何位置。

答案2

好的,这是我能找到的最接近我所寻找的东西了。

\documentclass[10pt,a4paper]{article}

\usepackage[titles]{tocloft}

\newcommand{\listexampletitle}{Recommendations}
\newlistof{examples}{exp}{\subsection{\listexampletitle}}

\newcommand{\examplelist}[1]{%
    \refstepcounter{examples}
    \addcontentsline{exp}{examples}{\textbullet~#1}%fake an itemize list by pushing textbullets in - if you use other bullets you need to change this
}
\newcommand{\example}[1]{\examplelist{#1}\textbf{Example} \theexamples{}: #1}
\cftsetindents{examples}{1.5em}{3.0em}
\cftpagenumbersoff{examples} % Don't print page numbers with examples
\setlength{\cftexamplesnumwidth}{1.5cm} % Add space around example numbers

\begin{document}
    
    \section{summary}
    \listofexamples
\section{some body text}
Lorizzle ipsum dolor sure \example{first example}
Dizzle shizznit dolizzle. 
    \example{second example}
\end{document}

相关内容