4

I am using \lstinputlisting to present some of my code in a paper. As shown in this image: enter image description here

I intend to add empty lines between different parts of codes. However, I somehow want to reduce the height of these empty lines since they are occupying too much space.

Is there any way that I can control the height only for the empty lines by config the \lstset?

Yu-Chih
  • 165

1 Answers1

6

There is a hook that you can use:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
abc
abc

abc
\end{lstlisting}


\makeatletter
\lst@AddToHook{OnEmptyLine}{\vspace{-0.7\baselineskip}}
\makeatother
\begin{lstlisting}
abc
abc

abc
\end{lstlisting}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261