如何修改清单中代码的字体。我尝试了 basicstyle = \sffamily,但似乎不起作用。现在我可以更改字体类型。但如何修改代码之间的间距。例如,1.5 倍行距。
代码如下:
\begin{listing}
\noindent
\begin{minipage}[b]{0.5\textwidth}
\begin{framed}
\begin{lstlisting}[gobble=16, language=C,numbers=left,numberstyle={\color{numbercolor}\normalfont},
numbersep={-0.5cm},keywordstyle={\color{keywordcolor}},basicstyle = \sffamily]
if (secret)
access line 0
else
access line 1
\end{lstlisting}
\captionof{subfigure}{Victim function}
\end{framed}
\end{minipage}%
\\[-0.15em]
\begin{minipage}[b]{0.5\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}{Victim function}
\end{framed}
\end{minipage}
\caption{subfigure}{Victim function}
\end{listing}
但我想要的是:
\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}