I want to use lstlisting to describe two pieces of code. But how can it be divided like this? In addition, can such a list use if else or for statements? What command controls (a) and (b) above the picture? Is it \caption?
If anyone can reproduce the Latex code for this picture, I would be more grateful. Thank you!
Thank you Willoughby for your help. The current result graph is like this.
But the current font is obviously not as good as the picture above. I would like to ask how to modify the font. I tried various methods, but there is no way. Finally read this post: set the font family for lstlisting. The font has changed, but it is still not as good as the picture above. How can I change to the above font? And how to modify the distance between (a), (b) caption and the box below?
\documentclass{article}
\usepackage{listings}
\usepackage{framed}
\usepackage{capt-of}
\usepackage{newfloat}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{keywordcolor}{RGB}{157,0,129}
\definecolor{commentcolor}{RGB}{157,0,129}
\definecolor{numbercolor}{RGB}{120,120,120}
\DeclareFloatingEnvironment[fileext=frm,placement={!ht},name=Listing]{listing}
\usepackage[ruled,lined]{algorithm2e}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{pifont}
\newlength{\restofline}
\usepackage{multirow}
\usepackage{tablefootnote}
\usepackage{lipsum} % Just for dummy text. Do not use in actual document.
\begin{document}
\lipsum
\begin{listing}[t]
\noindent
\centering
\begin{minipage}[b]{\textwidth}
\begin{framed}
\begin{lstlisting}[gobble=16, language=C,numbers=left,
numberstyle={\color{numbercolor}\normalfont},
numbersep={-0.5cm},keywordstyle={\color{keywordcolor}},
breaklines=true]
if (secret)
access line 0
else
access line 1
\end{lstlisting}
\captionof{subfigure}{function1}
\end{framed}
\end{minipage}%
\\[-0.15em]
\begin{minipage}[b]{\textwidth}
\begin{framed}
\begin{lstlisting}[gobble=16, language=C,numbers=left,numberstyle={\color{numbercolor}\normalfont},
numbersep={-0.5cm},keywordstyle={\color{keywordcolor}}]
if (secret)
access line 0
else
access line 1
\end{lstlisting}
\captionof{subfigure}{function2}
\end{framed}
\end{minipage}
\caption{exploitation}
\end{listing}
\lipsum
\end{document}



lstlistingsis a verbatim like environment, that means that all spaces are put in the document. If you wantnspaces of indentation that don't effect the output use the[gobble=n]option. Also verbatim environments won't automatically wrap text so if a line is too long it will just go off the page. Without seeing your code I can't say why a, b, etc. aren't displaying. As for changing the size given that your captions are all bold I'm guessing you have some global setting (maybe in a class) that is doing that and editing that may help – Willoughby Mar 22 '21 at 08:32