Can you please help me modify the listing names as shown in the image attached. I currently have 4 different \lstdefinestyle
and would like to then have 4 different listing names. I was trying to follow the solution given here to modify the listings names but I could not get the code to work properly.
Any help to get the listing names changed as shown in the image, is sincerely appreciated!
Here is my code:
\documentclass[a4paper, 10pt]{report}
\newcommand{\codeimg}{\includegraphics[scale=0.1]{example-image-a}}
\usepackage{calc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{pdfpages,graphicx}
\usepackage{mdframed}
\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}
%\renewcommand\lstlistingname{Code}
\lstset{
language=Python,
numbers=left,
numbersep= 7mm,
numberstyle=\color{Black},
stepnumber=1,
tabsize=3,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
basicstyle=\color{Black}\ttfamily,
commentstyle=\color{LimeGreen},
keywordstyle=\color{BurntOrange}\bfseries,
stringstyle=\color{WildStrawberry},
keywords={var, func, extends},
frame=leftline,
framesep=0mm,
xleftmargin=3mm,
framesep=2mm,
framerule=0mm,
abovecaptionskip=5mm,
aboveskip=\baselineskip,
belowskip=\baselineskip
}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,listings}
\newtcblisting[use counter=lstlisting]{codeblock}[2][]{%
enhanced,noparskip,breakable,colback=light-gray,colframe=DarkSlateGray,opacitybacktitle=.8,%
fonttitle=\bfseries,before upper={\hspace*{-1em}\includegraphics[height=\baselineskip]{example-image-a}~#2},%
title after break={\centering\footnotesize\itshape\strut\lstlistingname~\thelstlisting~--~continued},%
listing only,listing options={xleftmargin=-1mm},after upper={\centering\strut\lstlistingname~\thelstlisting:~#2},
frame hidden,arc=0pt,outer arc=0pt,boxrule=0pt,frame code={\draw[gray,line width=2mm] ([xshift=-0.5pt]frame.north west) -- ([xshift=-0.5pt]frame.south west);},#1}
\lstdefinestyle{mystyleresults}{
backgroundcolor=\color{backcolour},
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,
backgroundcolor=\color{myblueiii},
tabsize=6
}
\lstdefinestyle{mystylecode}{
language=C,
numbers=none,
commentstyle=\color{LimeGreen},
keywordstyle=\color{BurntOrange}\bfseries,
keywords={real},
backgroundcolor=\color{codegray!10}
}
\begin{filecontents}{result_1.txt}
=== Run information ===
Correlation coefficient 0.5941
Mean absolute error 2.2173
Root mean squared error 3.7905
Relative absolute error 76.7091 %
Root relative squared error 81.3406 %
Total Number of Instances 188
\end{filecontents}
\begin{filecontents}{result_2.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}
\begin{filecontents*}{sample.m}
% create a file for output
!touch testFile.txt
fid = fopen('testFile.text', 'w')
for i=1:10
fprintf(fid,'%6.2f \n', i);
end
\end{filecontents*}
\begin{document}
\lstinputlisting[
style=mystylecode,
caption={Code Snippet.},
label = R1]{result_2.txt}
\lstinputlisting[
style=mystyleresults,
caption={Results from run 1.},
label = bilateral1GPA]{result_1.txt}
\begin{codeblock}{Les bases de GDScript}
var nombreDeGardes = 4 #déclaration d'une variable
nombreDeGardes = plusDeux(nombreDeGardes) #appel d'une fonction avec la variable nombreDeGardes passée en paramètre
\end{codeblock}
\lstinputlisting[style=Matlab-editor,caption=Sample code from Matlab]{sample.m}
\end{document}
lstlisting
, so what do you expect?\newtcbinputlistings
instead of the\lstinputlistings
and usetcolorbox
features