0

I want to reduce all lines' height (empty space between each line) in \lstinputlisting, is it possible?

Original code is taken from https://tex.stackexchange.com/a/660320/127048 , only \usepackage[scale=0.9]{zi4} is changed (smaller scale):

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{amsmath,amssymb}
\usepackage{lipsum}
\usepackage[nott]{newtxtext}
\usepackage{newtxmath}
\usepackage[scale=0.9]{zi4}
\usepackage{listings}
\usepackage{lstautogobble}

\lstdefinestyle{mystyle} { basicstyle=\ttfamily, frame=single, breaklines, columns=fullflexible, breakindent=1.2em, breakatwhitespace, escapeinside={(}{)}, } \begin{document} abc\texttt{abc}

\begin{lstlisting}[style=mystyle,autogobble,xleftmargin=1.1mm,xrightmargin=2.5pt] function hello_world(,)(uint a, uint b, uint c, uint d, uint e, uint f) public returns bool { uint256 amount = 100 return true; } \end{lstlisting} \lipsum*[2] \end{document}

enter image description here

Could be related to: Reduce the height of empty lines in \lstinputlisting

David Carlisle
  • 757,742
alper
  • 1,389
  • is there really any space it is safe to remove? Your code is all lower case and has no descenders but add some gygyABC and the spacing is quite tight already? – David Carlisle Oct 04 '22 at 15:37
  • Yes sir quite tight already, I just wanted to gain very little space like maybe 1mm – alper Oct 04 '22 at 16:12

1 Answers1

2

You can specify the baselineskip as part of the font size, so

enter image description here


\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{amsmath,amssymb}
\usepackage{lipsum}
\usepackage[nott]{newtxtext}
\usepackage{newtxmath}
\usepackage[scale=0.9]{zi4}
\usepackage{listings}
\usepackage{lstautogobble}

\lstdefinestyle{mystyle}
{
    basicstyle=\fontsize{10}{10.5}\ttfamily,
    frame=single,
    breaklines,
    columns=fullflexible,
    breakindent=1.2em,
    breakatwhitespace,
    escapeinside={(*}{*)},
}
\begin{document}
abc\texttt{abc}


\begin{lstlisting}[style=mystyle,autogobble,xleftmargin=1.1mm,xrightmargin=2.5pt]
    function hello_world(*\,*)(uint a, uint b, uint c, uint d, uint e, uint f) public returns bool {
        uint256 amount = 100
        return true;
    }
\end{lstlisting}


\lipsum*[2]
\end{document}

David Carlisle
  • 757,742