![在列表文件第 2 部分中添加标注](https://linux22.com/image/351384/%E5%9C%A8%E5%88%97%E8%A1%A8%E6%96%87%E4%BB%B6%E7%AC%AC%202%20%E9%83%A8%E5%88%86%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%A0%87%E6%B3%A8.png)
这个问题源于此处发布了“在列表文件中添加标注”的解决方案。
修改后\newtcbinputlisting
,出现编译错误:
! Use of \tcb@@icolorbox doesn't match its definition. <argument> \def \reserved@a { \def \@currenvir {tikzpicture}\edef \@currenvli... l.74 Result from run 1}{result1.txt}
你能告诉我如何克服这个编译定义不匹配的问题吗?
修改后的代码如下:
\documentclass[a4paper, 10pt]{report}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{listings}
\usepackage{filecontents}
\usepackage[numbered,framed]{matlab-prettifier}
\usepackage{amsmath}
\definecolor{myblueiii}{RGB}{199,234,253}
\usepackage{tcolorbox}
\newcounter{result}
\tcbuselibrary{skins,breakable,listings}
\newtcbinputlisting[use counter=result,list inside=result,number within=chapter,list type=result]{\inputresult}[3][]{%listing options={style=mystyleresults},%
list text = {#2},
enhanced,noparskip,breakable,colback=myblueiii,colbacktitle = myblueiii,
title after break={\centering\footnotesize\itshape\bfseries\strut Result~\theresult~--~continued},%
listing only,listing options={xleftmargin=-1mm,#1,style=mystyleresults},after upper={\centering\strut{\bfseries Result~\theresult:}~#2},%
listing file={#3},#1}
\lstdefinestyle{mystyleresults}{
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
}
\begin{filecontents}{result1.txt}
=== Run information ===
Classifier Model
Bagging with 10 iterations and base learner
weka.classifiers.trees.J48 -C 0.25 -M 2
Cost Matrix
0 1
1 0
Time taken to build model: 0.01 seconds
=== Stratified cross-validation ===
=== Summary ===
Correctly Classified Instances 166 88.2979 %
Incorrectly Classified Instances 22 11.7021 %
Kappa statistic 0.7173
\end{filecontents}
\begin{document}
\inputresult{%
\begin{tikzpicture}[overlay,xshift=-5cm,yshift=3.75cm]%% Get (0,0) in the right place
\node[draw, fill=red,opacity=0.3,rounded corners=2mm,anchor=west,minimum height=10mm,minimum width=21mm]{};
\draw[line width=1.5pt,-latex](2.1,0)-- (3.5,0);
\node[anchor=west,text width=16mm] at (3.5,0) {\textcolor{red}{\textsf{\footnotesize cost matrix change from}}};
\node[anchor=west] at (5.5,0) {\textcolor{red}{\footnotesize$%
\begin{matrix}
\mathsf{0} & \mathsf{1}\\ \mathsf{1} & \mathsf{0}
\end{matrix}$}};
\draw[line width=1.5pt,-latex](6.5,0)-- +(1,0);
\node[anchor=west] at (7.5,0) {\textcolor{red}{\footnotesize$%
\begin{matrix}
\mathsf{0} & \mathsf{10}\\ \mathsf{10} & \mathsf{0}
\end{matrix}$}};
\end{tikzpicture}%
Result from run 1}{result1.txt}
\end{document}
答案1
显然,新设置不允许您将图片放在标题内。相反,您可以将其直接放在列表框后面。这意味着更改图片的位置。由于[overlay]
使用了该选项,因此图片不占用任何空间。我还添加了\lipsum
s 以查看列表前后的间距。
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1]
\inputresult{Result from run 1}{result1.txt}
\begin{tikzpicture}[overlay,xshift=-0.15cm,yshift=4.7cm]%% Get (0,0) in the right place
\node[draw, fill=red,opacity=0.3,rounded corners=2mm,anchor=west,minimum height=10mm,minimum width=21mm]{};
\draw[line width=1.5pt,-latex](2.1,0)-- (3.5,0);
\node[anchor=west,text width=16mm] at (3.5,0) {\textcolor{red}{\textsf{\footnotesize cost matrix change from}}};
\node[anchor=west] at (5.5,0) {\textcolor{red}{\footnotesize$%
\begin{matrix}
\mathsf{0} & \mathsf{1}\\ \mathsf{1} & \mathsf{0}
\end{matrix}$}};
\draw[line width=1.5pt,-latex](6.5,0)-- +(1,0);
\node[anchor=west] at (7.5,0) {\textcolor{red}{\footnotesize$%
\begin{matrix}
\mathsf{0} & \mathsf{10}\\ \mathsf{10} & \mathsf{0}
\end{matrix}$}};
\end{tikzpicture}%
\lipsum[2]