0

How to modify the font of the code in the listing. I tried basicstyle = \sffamily and it didn't seem to work. Now I can change the font type. But How to modify the spacing between codes. For example, 1.5 times the line spacing.

The code is:

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

The result is : enter image description here

But what I want is:

enter image description here

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

Gerrie
  • 271
  • It looks like what you want is a monospaced font, try basicstyle=\ttfamily – Willoughby Mar 22 '21 at 08:43
  • thank you! I added details and code. – Gerrie Mar 22 '21 at 08:45
  • Setting columns=flexible or columns=fullflexible in the lstlisting options might be closer to your desired output. – Marijn Mar 22 '21 at 14:46
  • See also https://tex.stackexchange.com/questions/33020/shrinking-monospace-style-for-listings-package or https://tex.stackexchange.com/questions/117533/is-it-possible-to-use-a-non-monospace-font-in-verbatim-environments or https://tex.stackexchange.com/questions/378617/getting-narrower-text-within-lstlistings. – Marijn Mar 22 '21 at 14:49
  • Is the problem solved? Please make sure to follow-up or delete the question if not relevant any more – Dr. Manuel Kuehner Mar 23 '21 at 03:39

0 Answers0