4

How can I create an additional List to appear in the TOC referencing a custom environment? Working on Overleaf, I've unsuccessfully tried applying the answers from the following questions, and I can't understand why:

list of newcounter
Generating lists of custom environment.?
Customized 'list of...'?

Below is my MWE. It is the first time I ask, so excuse me if I haven't managed to get rid of unnecessary code. Let me know if you want me to edit it. Thanks.

\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}
Lukitah
  • 43
  • 5
  • 99 % of the packages are not needed all for your question. hyperref is loaded too early –  Dec 27 '17 at 19:01
  • So you want the data environment to be captured in the ToC? Do you want it in a separate ToC-like display, or just added to the existing ToC? What do you want it to look like? – Werner Dec 27 '17 at 19:06
  • I wanted to have data environments listed in an additional List similar to the LoF and LoT. @Christian's answer does exactly this. However, I can't add this new List to the ToC nor format it as the LoF and LoT. For the latter, this question's answers are not working: [https://tex.stackexchange.com/questions/58469/why-are-listof-and-listoffigures-styled-differently]. – Lukitah Dec 28 '17 at 11:57
  • Adding \cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{\listofdataextractsname} before \listofdataextractsinserts the new List to the ToC. – Lukitah Dec 28 '17 at 12:19

1 Answers1

2

The easiest way seems to use \newlistof from tocloft and providing for a bunch of macros that can be adjusted for the look and feel of the \listofdataextracts.

I renamed the counter to dataextracts and put an \addcontentsline statement inside in order to write to a .dat file which is the .toc file for the `data extracts.

The \newlistof[chapter]{dataextracts}{dat}{\listofdataextractsname} call defines \listofdataextracts and some other macros that not relevant here, it provides the counter dataextracts as well and resets it within 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}

With entry to 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}

enter image description here

  • Your answer works perfectly, Christian, thank you. I think the position of the hyperref package was problematic, indeed. Now I have additional issues that for the moment I don't manage to solve, such as adding this new list to the TOC and having the same format as the lof and lot, but I guess it's better to create a follow-up question. Thanks again. – Lukitah Dec 28 '17 at 11:59
  • @Lukitah: Please accept my solution then –  Dec 28 '17 at 13:08
  • Done, Christian. Excuse me: first time! – Lukitah Dec 28 '17 at 13:23
  • @Lukitah: I've added the automatic ToC entry as a gift -- see the 2nd version at the end;-) Happy TeXing –  Dec 28 '17 at 13:26
  • it works perfectly! Thank you very much :)! – Lukitah Dec 28 '17 at 13:36
  • I get the impression that tocloft does not work with beamer: it is trying to redefine a bunch of commands such l@section that probably don't exist. – Victor Eijkhout May 18 '20 at 16:53