目录中的 \newenvironment 列表

目录中的 \newenvironment 列表

如何创建一个附加列表以引用自定义环境显示在目录中?在 Overleaf 上工作时,我尝试应用以下问题的答案,但没有成功,我不明白为什么:

新品计数器列表
生成自定义环境列表。
定制的‘...列表’

以下是我的 MWE。这是我第一次问,所以如果我没有设法去掉不必要的代码,请原谅。如果你想让我编辑它,请告诉我。谢谢。

\documentclass[12pt,twoside]{book} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, american]{babel}
\usepackage[autostyle]{csquotes}
\usepackage[a4paper, margin=3cm]{geometry}

\usepackage[style=apa,backend=biber, natbib]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{References/library.bib}

\usepackage{booktabs} 
\usepackage{multirow}
\usepackage{threeparttable} 
\usepackage{longtable}
\usepackage{adjustbox}
\usepackage{array} 
\usepackage{graphicx}
\usepackage[justification=centering]{caption}
\usepackage{subcaption}
\usepackage{epigraph}
\usepackage[toc,page]{appendix}
\usepackage{rotfloat} 
\usepackage{hyperref}
\usepackage{microtype}
\usepackage{todonotes}
\usepackage{ifthen}
\usepackage[raggedright]{titlesec}
\usepackage{tocstyle}
\usetocstyle{standard}
\usepackage{pdfpages}

%packages for \newenviroment data
\usepackage{xcolor}
\usepackage{amsmath} 
\newcounter{mydata}
\newenvironment{data}[1]
{%
\par%
\addvspace{\baselineskip}%
\refstepcounter{mydata}%
    {\centering {Extract \themydata: #1}\par}%
    \addvspace{0.5\baselineskip}%
%\\%
}{%
\par%
\addvspace{0.5\baselineskip}%
}%
\numberwithin{mydata}{chapter}

\usepackage{paracol}
\footnotelayout{m}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{emptypage} 
\usepackage[intoc]{nomencl}
\usepackage{enumitem}

\usepackage[nottoc]{tocbibind} 
\usepackage{tocloft}

\begin{document}
\pagestyle{empty}
\frontmatter

\tableofcontents
\listoffigures
\listoftables

\mainmatter
\pagestyle{fancy}
\chapter{Intro}
bla bla
\section{First section}

\begin{data}{My first Extract.}
   First Extract data
\end{data}

\chapter{Second chapter}
\section{First section}

\begin{data}{My second Extract.}
   First Extract data
\end{data}

\end{document}

答案1

最简单的方法似乎是使用\newlistoftocloft提供一组可以根据外观和感觉进行调整的宏\listofdataextracts

我将计数器重命名为,dataextracts并在里面放入一个\addcontentsline语句,以便写入.dat文件,该文件是.toc“数据提取”的文件。

\newlistof[chapter]{dataextracts}{dat}{\listofdataextractsname}调用定义\listofdataextracts和一些其他与此不相关的宏,它还提供了计数器dataextracts并在其中重置它chapter

\documentclass[12pt,twoside]{book} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, american]{babel}
\usepackage[autostyle]{csquotes}
\usepackage[a4paper, margin=3cm,headheight=15pt]{geometry}




\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{amsmath} 

\usepackage[nottoc]{tocbibind} 
\usepackage{tocloft}

\usepackage{hyperref}


\newcommand{\listofdataextractsname}{List of Data}

\newlistof[chapter]{dataextracts}{dat}{\listofdataextractsname}



\newenvironment{data}[1]{%
  \par%
  \addvspace{\baselineskip}%
  \refstepcounter{dataextracts}%
  {\centering {Extract \thedataextracts: #1}\par}%
  \addcontentsline{dat}{dataextracts}{\protect\numberline{\thedataextracts}#1}%
  \addvspace{0.5\baselineskip}%
  % \\%
}{%
  \par%
  \addvspace{0.5\baselineskip}%
}%





\begin{document}
\pagestyle{empty}
\frontmatter

\tableofcontents
\listoffigures
\listoftables

\listofdataextracts

\mainmatter
\pagestyle{fancy}
\chapter{Intro}
bla bla
\section{First section}

\begin{data}{My first Extract.}
   First Extract data
\end{data}

\chapter{Second chapter}
\section{First section}

\begin{data}{My second Extract.}
   Second Extract data
\end{data}

\end{document}

进入 ToC

\documentclass[12pt,twoside]{book} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, american]{babel}
\usepackage[autostyle]{csquotes}
\usepackage[a4paper, margin=3cm,headheight=15pt]{geometry}




\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{amsmath} 

\usepackage[nottoc]{tocbibind} 
\usepackage{tocloft}

\usepackage{hyperref}


\newcommand{\listofdataextractsname}{List of Data}

\newlistof[chapter]{dataextracts}{dat}{\listofdataextractsname}



\makeatletter
\let\listofdataextractsorig\listofdataextracts% Store original version
\renewcommand{\listofdataextracts}{%
  \cleardoublepage\phantomsection\addcontentsline{toc}{chapter}{\listofdataextractsname}% Add toc line
  \listofdataextractsorig
}
\makeatother


\newenvironment{data}[1]{%
  \par%
  \addvspace{\baselineskip}%
  \refstepcounter{dataextracts}%
  {\centering {Extract \thedataextracts: #1}\par}%
  \addcontentsline{dat}{dataextracts}{\protect\numberline{\thedataextracts}#1}%
  \addvspace{0.5\baselineskip}%
  % \\%
}{%
  \par%
  \addvspace{0.5\baselineskip}%
}%





\begin{document}
\pagestyle{empty}
\frontmatter

\tableofcontents
\listoffigures
\listoftables

\listofdataextracts

\mainmatter
\pagestyle{fancy}
\chapter{Intro}
bla bla
\section{First section}

\begin{data}{My first Extract.}
   First Extract data
\end{data}

\chapter{Second chapter}
\section{First section}

\begin{data}{My second Extract.}
   Second Extract data
\end{data}

\end{document}

在此处输入图片描述

相关内容