2

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?

  • 1
    Welcome to TeX.SE!. Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Cragfelt Nov 30 '17 at 22:01
4

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

|improve this answer|||||
  • Works perfectly, very smart solution. Thanks – Yu-Chih Nov 30 '17 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.