来自解决方案发布在这里,我想让其\newtcbinputlisting
显示在目录中。
我尝试使用\lstlistoflistings
,但列表内容页面中没有任何内容显示。
我希望列表显示在各自的部分中,但在列表下,如下所示:
房源
数据
1.1 代码片段................................3
1.2 代码片段..................................3
结果
1.1 第一次运行的结果......................3
到目前为止的代码如下:
\documentclass[a4paper, 10pt]{book}
\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{listings}
\usepackage{filecontents}
\usepackage[numbered,framed]{matlab-prettifier}
\definecolor{light-gray}{gray}{0.92}
\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mainColor}{RGB}{211, 47, 47} % some dark red
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueiii}{RGB}{199,234,253}
\usepackage{tcolorbox}
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}
\tcbuselibrary{skins,breakable,listings}
\newtcbinputlisting[use counter=data]{\inputdata}[3][]{%
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]{\inputresult}[3][]{%
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,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=none,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=6
}
\lstdefinestyle{weka}{
numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{codegray},
commentstyle=\color{codegreen},
keywordstyle=\color{blue},
keywordstyle={[2]\color{magenta}},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
comment=[l]{\%},
keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\begin{filecontents}{result1.txt}
=== Run information ===
Correlation coefficient 0.5941
Mean absolute error 2.2173
\end{filecontents}
\begin{filecontents}{result2.txt}
% 9 attributes
% 188 instances
@relation FIT
@attribute NUMUORS real % Number of unique operators
@attribute NUMUANDS real % Number of unique operands
@attribute TOTOTORS real % Total number of operators
\end{filecontents}
\usepackage{hyperref}
\numberwithin{data}{chapter}
\numberwithin{result}{chapter}
\newcommand{\dataref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Data \ref{#1}}}%
}
\newcommand{\resultref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Result \ref{#1}}}%
}
\begin{document}
\chapter{Data}
\section{Data1}
This is a reference for \dataref{data:D1} shown below.
\inputdata[label={data:D1}]{Code Snippet}{result2.txt}
This is a reference for \dataref{data:D2} shown below.
\inputdata[label={data:D2}]{Code Snippet}{result2.txt}
This is a reference for \dataref{result:R1} shown below.
\inputresult[label={result:R1}]{Result from run 1}{result1.txt}
This is a reference for \resultref{result:R1} shown above.
\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{Code Snippet}{result2.txt}
\end{document}
答案1
使用list inside=data
或list inside=result
选项\tcblistof[\chapter*]{data}{List of Data}
等命令来生成并显示list of...
以生成单独的列表。
该命令\tcblistof[\chapter*]{data}{List of Data}
将用作\chapter*
列表的标题命令,标题将是List of Data
——任何其他名称或分段单元也是可能的,也可以作为任意命令,而不是\chapter*
使用一个参数作为gobble
列表的名称。
必须提供title=
或list entry=
,请根据需要更改键值。
有不但是,这是一种对数据条目和结果条目进行分组的简单方法Listings
。
实际上,在我看来,它们根本不是列表。
\documentclass[a4paper, 10pt]{book}
\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{listings}
\usepackage{filecontents}
\usepackage[numbered,framed]{matlab-prettifier}
\definecolor{light-gray}{gray}{0.92}
\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mainColor}{RGB}{211, 47, 47} % some dark red
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueiii}{RGB}{199,234,253}
\usepackage{tcolorbox}
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}
\usepackage{hyperref}
\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,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=none,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=6
}
\lstdefinestyle{weka}{
numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{codegray},
commentstyle=\color{codegreen},
keywordstyle=\color{blue},
keywordstyle={[2]\color{magenta}},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
comment=[l]{\%},
keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\begin{filecontents}{result1.txt}
=== Run information ===
Correlation coefficient 0.5941
Mean absolute error 2.2173
\end{filecontents}
\begin{filecontents}{result2.txt}
% 9 attributes
% 188 instances
@relation FIT
@attribute NUMUORS real % Number of unique operators
@attribute NUMUANDS real % Number of unique operands
@attribute TOTOTORS real % Total number of operators
\end{filecontents}
%\numberwithin{data}{chapter}
%\numberwithin{result}{chapter}
\newcommand{\dataref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Data \ref{#1}}}%
}
\newcommand{\resultref}[1]{%
\hyperref[#1]{\textbf{\color{mybluei}Result \ref{#1}}}%
}
\newcommand{\listofdataname}{List of Data}
\newcommand{\listofresultname}{List of Results}
\begin{document}
\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}
This is a reference for \dataref{data:D2} shown below.
\inputdata[label={data:D2}]{Code Snippet}{result2.txt}
This is a reference for \dataref{result:R1} shown below.
\inputresult[label={result:R1}]{Result from run 1}{result1.txt}
This is a reference for \resultref{result:R1} shown above.
\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{Code Snippet}{result2.txt}
\end{document}