谢谢Christian Hupfer 博士,他能够生成一个我的“数据”和“结果”代码的目录。我试图进一步完善他的解决方案,让列表目录像我当前的图表列表一样显示:
目前,“数据列表”和“结果列表”显示如下:
(章节列表与图表列表之间的字体和间距不同)。
我正在使用\newtcbinputlisting
环境最初由格诺特。
我正在使用titletoc
和titlesec
,但我没有获得与图形列表相同的数据和结果列表的效果。
您能告诉我如何才能让新定义的列表看起来像图片列表一样吗?谢谢!
到目前为止的代码如下:
\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}
答案1
不同章节图形之间的垂直间距由命令引入,与等或设置\chapter
无关。titletoc
\tcblistof
该\chapter
命令没有意识到应该为.data
和.result
列表添加这个空间。
.lot
然而,这可以通过使用与对and所做的相同的语句.lof
并将其添加到\chapter
命令前面来解决。
\usepackage{xpatch}
\xpretocmd{\chapter}{%
\addtocontents{data}{\protect\addvspace{10pt}}
\addtocontents{result}{\protect\addvspace{10pt}}
}{}{}
当然,的值10pt
可以随意改变......
但是,即使没有数据或结果框,这也会将这些空格添加到相关列表中。可以使用包来实现更好的方法,xcntperchap
以跟踪每个章节的数据或结果框数量等——这将产生控制是否应该有条目的方法。
\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}