1

Thanks to Dr. Christian Hupfer, he was able to generate a table of contents for my "Data" and "Results" code. I was attempting to further his solution to have the Lists toc show up like my current List of Figures:

enter image description here

Currently, the "List of Data" and "List of Results" show up like this:

enter image description here

(the font and spacing between chapter list is different as compared to the List of Figures).

I am using a \newtcbinputlisting environment that was originally developed by gernot.

I am using titletoc and titlesec, but I am not getting the same effect of the Data and Results list as I get for my Figures list.

Can you direct me as to how I can get the newly defined lists appear like the List of Figures? Thanks!

Here is the code thus far:

\documentclass[a4paper, 10pt]{book}

\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{listings}
\usepackage{filecontents}

\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}

%======================================================================================
%   CHAPTER HEADINGS
%======================================================================================
\newcommand{\listofdataname}{List of Data}
\newcommand{\listofresultname}{List of Results}

\usepackage{titletoc}

\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}

\usepackage[explicit,calcwidth]{titlesec}
\usepackage{fourier}

% List of figures
\titlecontents{figure}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

% List of data
\titlecontents{data}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

% List of data
\titlecontents{result}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

\usepackage{tcolorbox}
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}

%======================================================================================
%   HYPERLINKS IN THE DOCUMENTS
%======================================================================================

\usepackage{hyperref}
\hypersetup{colorlinks=true,
            linkcolor = myblueii,
            backref=true,
            %pagebackref=true,
            hyperindex=true,
            breaklinks=true,
            urlcolor=blue,
            citecolor = ocre,
            bookmarks=true,
            bookmarksopen=false,
            pdftitle={Title},
            pdfauthor={Author}}

\tcbuselibrary{skins,breakable,listings}
\newtcbinputlisting[use counter=data,list inside=data,number within=chapter]{\inputdata}[3][]{%
  title={Data~\thedata~ #2},
  title after break={\centering\footnotesize\itshape\strut Data~\thedata~--~continued},%
  listing only,listing options={xleftmargin=-1mm,#1,style=weka},after upper={\centering\strut Data~\thedata:~#2},%
  listing file={#3},#1}
\newtcbinputlisting[use counter=result,list inside=result,number within=chapter]{\inputresult}[3][]{%
  title={#2},
  enhanced,noparskip,breakable,colback=myblueiii,opacitybacktitle=.8,%
  title after break={\centering\footnotesize\itshape\strut Result~\theresult~--~continued},%
  listing only,listing options={xleftmargin=-1mm,#1,style=mystyleresults},after upper={\centering\strut Result~\theresult:~#2},%
  listing file={#3},#1}

\lstdefinestyle{mystyleresults}{
    commentstyle=\color{codegreen},
    keywordstyle=\color{black},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{black},
    basicstyle=\ttfamily\footnotesize
}

\lstdefinestyle{weka}{
    numbers=none,
    numbersep=5pt,
    numberstyle=\tiny\color{codegray},
    commentstyle=\color{codegreen},
}

\begin{filecontents}{result1.txt}
=== Run information ===

Correlation coefficient                  0.5941
Mean absolute error                      2.2173
\end{filecontents}

\begin{filecontents}{result2.txt}

@attribute NUMUORS real   % Number of unique operators
@attribute NUMUANDS real  % Number of unique operands
@attribute TOTOTORS real  % Total number of operators

\end{filecontents}

\newcommand{\dataref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Data \ref{#1}}}%
}

\newcommand{\resultref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Result \ref{#1}}}%
}

\begin{document}

\listoffigures
\tcblistof[\chapter*]{data}{\listofdataname}
\tcblistof[\chapter*]{result}{\listofresultname}

\chapter{Data}
\section{Data1}
This is a reference for \dataref{data:D1} shown below.
\inputdata[label={data:D1}]{Code Snippet}{result2.txt}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-a}
\caption[Weka Preprocess Window for Fit.arff Data]{Weka Preprocess Window for Fit.arff Data.}
\end{figure}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit2.arff Data]{Weka Preprocess Window for Fit2.arff Data.}
\end{figure}

This is a reference for \dataref{data:D2} shown below.
\inputresult[label={data:D2}]{Code Snippet}{result1.txt}

\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{Code Snippet}{result2.txt}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Test.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}

\end{document} 
2
  • The reason is that \chapter does not add empty vertical space to the .data file etc. like it does for .lot or .lot. Don't use titlesec etc. for this!
    – user31729
    Commented Feb 13, 2017 at 22:55
  • Does any of your chapters have at least one result and data box?
    – user31729
    Commented Feb 13, 2017 at 23:03

1 Answer 1

4

The vertical spacing between figures from different chapters is introduced by the \chapter command and has nothing to do with titletoc etc. or \tcblistof settings.

The \chapter command is not aware of the fact that it should add this space for the .data and .result lists.

This can be cured, however, with the same statements as is done for .lot and .lof and prepending it to the \chapter command, for example.

\usepackage{xpatch}

\xpretocmd{\chapter}{%
  \addtocontents{data}{\protect\addvspace{10pt}}
  \addtocontents{result}{\protect\addvspace{10pt}}
}{}{}

Of course, the value of 10pt can be changed at will...

However, this will add such spaces also to the relevant lists even if there's no data or result box. A better approach could be achieved with the xcntperchap package to trace the number of data or result boxes per chapter etc -- this will yield the means to control whether there should be an entry at all.

\documentclass[a4paper, 10pt]{book}

\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{filecontents}

\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}

%======================================================================================
%   CHAPTER HEADINGS
%======================================================================================
\newcommand{\listofdataname}{List of Data}
\newcommand{\listofresultname}{List of Results}

\usepackage{titletoc}

\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}

\usepackage[explicit,calcwidth]{titlesec}
\usepackage{fourier}

% List of figures
\titlecontents{figure}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

% List of data
\titlecontents{data}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]

% List of data
\titlecontents{result}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]


\usepackage[skins,breakable,listings]{tcolorbox}
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}

\usepackage{xpatch}

\xpretocmd{\chapter}{%
  \addtocontents{data}{\protect\addvspace{10pt}}
  \addtocontents{result}{\protect\addvspace{10pt}}
}{}{}


%======================================================================================
%   HYPERLINKS IN THE DOCUMENTS
%======================================================================================

\usepackage{hyperref}
\hypersetup{colorlinks=true,
            linkcolor = myblueii,
            backref=true,
            %pagebackref=true,
            hyperindex=true,
            breaklinks=true,
            urlcolor=blue,
            citecolor = ocre,
            bookmarks=true,
            bookmarksopen=false,
            pdftitle={Title},
            pdfauthor={Author}}

\newtcbinputlisting[use counter=data,list inside=data,number within=chapter]{\inputdata}[3][]{%
  title={Data~\thedata~ #2},
  title after break={\centering\footnotesize\itshape\strut Data~\thedata~--~continued},%
  listing only,listing options={xleftmargin=-1mm,#1,style=weka},after upper={\centering\strut Data~\thedata:~#2},%
  listing file={#3},#1}
\newtcbinputlisting[use counter=result,list inside=result,number within=chapter]{\inputresult}[3][]{%
  title={#2},
  enhanced,noparskip,breakable,colback=myblueiii,opacitybacktitle=.8,%
  title after break={\centering\footnotesize\itshape\strut Result~\theresult~--~continued},%
  listing only,listing options={xleftmargin=-1mm,#1,style=mystyleresults},after upper={\centering\strut Result~\theresult:~#2},%
  listing file={#3},#1}

\lstdefinestyle{mystyleresults}{
    commentstyle=\color{codegreen},
    keywordstyle=\color{black},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{black},
    basicstyle=\ttfamily\footnotesize
}

\lstdefinestyle{weka}{
    numbers=none,
    numbersep=5pt,
    numberstyle=\tiny\color{codegray},
    commentstyle=\color{codegreen},
}

\begin{filecontents}{result1.txt}
=== Run information ===

Correlation coefficient                  0.5941
Mean absolute error                      2.2173
\end{filecontents}

\begin{filecontents}{result2.txt}

@attribute NUMUORS real   % Number of unique operators
@attribute NUMUANDS real  % Number of unique operands
@attribute TOTOTORS real  % Total number of operators

\end{filecontents}

\newcommand{\dataref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Data \ref{#1}}}%
}

\newcommand{\resultref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Result \ref{#1}}}%
}

\begin{document}

\listoffigures
\tcblistof[\chapter*]{data}{\listofdataname}
\tcblistof[\chapter*]{result}{\listofresultname}

\chapter{Data}
\section{Data1}
This is a reference for \dataref{data:D1} shown below.
\inputdata[label={data:D1}]{Code Snippet}{result2.txt}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-a}
\caption[Weka Preprocess Window for Fit.arff Data]{Weka Preprocess Window for Fit.arff Data.}
\end{figure}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit2.arff Data]{Weka Preprocess Window for Fit2.arff Data.}
\end{figure}

This is a reference for \dataref{data:D2} shown below.
\inputresult[label={data:D2}]{Code Snippet}{result1.txt}

\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{Code Snippet}{result2.txt}

\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Test.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}

\end{document} 

enter image description here

8
  • Thanks for your solution! Just a little tweak...the list numbers should be not be hyperlinked and appear black like the List of Figures...is this an easy fix?
    – Joe
    Commented Feb 13, 2017 at 23:55
  • 2
    @Joe: No, no easy fix for the links. The colour is some titletoc issue, I won't attack that. In fact, you're construction a fragile building, actually, by adding one feature after another one -- this isn't good.
    – user31729
    Commented Feb 13, 2017 at 23:58
  • The xpatch works a bit like a document hook, doesnt it? Commented Feb 14, 2017 at 9:27
  • @MaestroGlanz: Well, like a macro hook rather.
    – user31729
    Commented Feb 14, 2017 at 9:45
  • 1
    @Joe: What is the name of the listing? Please read the tcolorbox manual, p. 110 of current version (3.96), on Lists of tcolorboxes. If you want to achieve a completely different view of the toc entries, you have to change the \l@data etc. definitions. I won't do this, however.
    – user31729
    Commented Feb 14, 2017 at 22:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .