![更改 \tcolorbox tcblistof 字体格式以匹配文档的其他列表](https://linux22.com/image/349612/%E6%9B%B4%E6%94%B9%20%5Ctcolorbox%20tcblistof%20%E5%AD%97%E4%BD%93%E6%A0%BC%E5%BC%8F%E4%BB%A5%E5%8C%B9%E9%85%8D%E6%96%87%E6%A1%A3%E7%9A%84%E5%85%B6%E4%BB%96%E5%88%97%E8%A1%A8.png)
此代码是根据解决方案构建的由 Hupfer 博士发布于此。
我试图使字体和其他格式tcblistof
与文档中的其他列表相匹配(例如图形列表 - 参见下图)。
tcblistof
外貌:
我希望此数据列表看起来像图表列表:
以下是迄今为止设计的代码:
\documentclass[a4paper, 10pt,oneside]{book}
\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{filecontents}
\usepackage{titletoc}
\usepackage{tikz}
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{fourier}
\usepackage[skins,breakable,listings]{tcolorbox}
\usepackage{xpatch}
\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\newcommand{\listofdataname}{List of Data}
\newcommand{\listofresultname}{List of Results}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}
% 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 results
\titlecontents{result}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}
\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][]{%
list text = {#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][]{%
list text = {#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}}}%
}
\makeatletter
\def\tcb@addcontentsline#1#2{%
\ifx\kvtcb@listentry\@empty%
\ifx\kvtcb@title\@empty%
\ifx\tcbtitletext\@empty%
\addcontentsline{#1}{#2}{{\ignorespaces\kvtcb@savedelimiter}}%
\else%
\addcontentsline{#1}{#2}{{\ignorespaces\tcbtitletext}}%
\fi%
\else%
\addcontentsline{#1}{#2}{{\ignorespaces\kvtcb@title}}%
\fi%
\else%
\addcontentsline{#1}{#2}{\kvtcb@listentry}%
\fi%
}
\renewcommand{\l@tcolorbox}{\@dottedtocline{1}{0em}{2.3em}}
\makeatother
\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}]{CodeAA Snippet for data AA}{result2.txt}
This is a reference for \dataref{data:D1} shown below.
\inputdata[label={data:D1}]{CodeBB Snippet for data BB}{result2.txt}
\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}
This is a reference for \dataref{data:D2} shown below.
\inputresult[label={data:D2}]{Data A Result Snippet}{result1.txt}
\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit22.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}
\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{CodeBB 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
必须使用等设置list type=data
,但是这还不够。
由于某种原因,titletoc
没有定义\ttll@data
等,因此必须手动完成,即\renewcommand{\ttll@data}{-1000}
(具有与相同的效果)\ttll@figure
。
\documentclass[a4paper, 10pt,oneside]{book}
\usepackage{amsmath}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{fourier}
\usepackage[skins,breakable,listings]{tcolorbox}
\usepackage{titletoc}
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{xpatch}
\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\newcommand{\listofdataname}{List of Data}
\newcommand{\listofresultname}{List of Results}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}
% 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 results
\titlecontents{result}[0em]
{\addvspace{2pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
\newcounter{data}
\newcounter{result}
\newcounter{pythoncode}
\newcounter{matlab}
\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,list type=data]{\inputdata}[3][]{%
list text = {#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,list type=result]{\inputresult}[3][]{%
list text = {#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}}}%
}
\makeatletter
\newcommand{\ttll@data}{-1000}
\newcommand{\ttll@result}{-1000}
\makeatother
\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}]{CodeAA Snippet for data AA}{result2.txt}
This is a reference for \dataref{data:D1} shown below.
\inputdata[label={data:D11}]{CodeBB Snippet for data BB}{result2.txt}
\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}
This is a reference for \dataref{data:D2} shown below.
\inputresult[label={data:D2}]{Data A Result Snippet}{result1.txt}
\begin{figure}[!htbt]
\includegraphics[scale=0.6]{example-image-b}
\caption[Weka Preprocess Window for Fit22.arff Data]{Weka Preprocess Window for Test.arff Data.}
\end{figure}
\chapter{Analysis}
\section{Data44}
This is a reference for \dataref{data:D44} shown below.
\inputdata[label=data:D44]{CodeBB 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}