使用 scrartcl 与 \newtcbinputlisting 时出现编译错误

使用 scrartcl 与 \newtcbinputlisting 时出现编译错误

我收到错误:

\cl@chapter ->\cl@chapter @elt {pythoncode} l.239 列表文件={#3},#1}

当使用scrartcldocumentclass时\newtcbinputlisting。你能告诉我如何修复这个错误吗?

代码

\documentclass[
10pt, % Main document font size
letterpaper, % Paper type, use 'letterpaper' for US Letter paper
oneside, % One page layout (no page indentation)
%twoside, % Two page layout (page indentation for binding and different headers)
headinclude,footinclude, % Extra spacing for the header and footer
BCOR5mm, % Binding correction
]{scrartcl}

\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} 

答案1

该课程scrartcl没有章节。

替换number within=chapternumber within=section、所有出现的\section带有\subsection以及所有出现的\chapter带有\section

\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*}


\documentclass[
  10pt, % Main document font size
  letterpaper, % Paper type, use 'letterpaper' for US Letter paper
  oneside, % One page layout (no page indentation)
  %twoside, % Two page layout (page indentation for binding and different headers)
  headinclude,footinclude, % Extra spacing for the header and footer
  BCOR5mm, % Binding correction
]{scrartcl}

\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=section,
]{\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=section,
]{\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
}

%\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[\section*]{data}{\listofdataname}
\tcblistof[\section*]{result}{\listofresultname}


\section{Data}
\subsection{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.

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

请注意,我使用了filecontents*此方法,因此写出的文件的开头没有添加任何内容。

在此处输入图片描述

相关内容