1

how could I reduce interline space in lstlisting?

\begin{lstlisting}[basicstyle=\linespread{0.8}\listingsfont]

Does not work for me and it says:

Fatal fontspec error: "cannot-use-pdftex" The fontspec package requires either XeTeX or LuaTeX. You must change your typesetting engine to, e.g., "xelatex" or "lualatex"instead of plain "latex" or "pdflatex". For immediate help type H .

But I am not sure I want to change that. Are there other ways?

1
  • 1
    The error message has nothing to do with listings. If you load fontspec, then you must use either XeLaTeX or LuaLaTeX. Can you show a minimal example?
    – egreg
    Sep 29, 2016 at 7:09

2 Answers 2

1

I solved putting before and after the listing

\begin{spacing}{0.5}
...
\end{spacing}
0

This has nothing to do with fontspec. Define suitably \listingsfont.

\documentclass{article}
\usepackage{listings}

\newcommand{\listingsfont}{\ttfamily}

\begin{document}

Normal interline space
\begin{lstlisting}[basicstyle=\listingsfont]
abc
def
ghi
\end{lstlisting}

Shortened interline space
\begin{lstlisting}[basicstyle=\linespread{0.8}\listingsfont]
abc
def
ghi
\end{lstlisting}

\end{document}

enter image description here

5
  • But that does not work. I get the fatal error above quoted
    – Klapaucius
    Oct 2, 2016 at 20:36
  • @Klapaucius Without a minimal example showing what you're doing, how can you expect more than a generic answer? How are you defining \listingsfont? Of course, if you load fontspec you must compile with XeLaTeX or LuaLaTeX.
    – egreg
    Oct 2, 2016 at 20:41
  • But whit the way I found it works even without compiling with one of those two
    – Klapaucius
    Oct 2, 2016 at 20:59
  • @Klapaucius I voted for closing, because the question is very unclear. If you're satisfied with a kludge, good for you; but I'd much prefer a real answer.
    – egreg
    Oct 2, 2016 at 21:00
  • for me we can close it, np
    – Klapaucius
    Oct 2, 2016 at 21:08

Not the answer you're looking for? Browse other questions tagged .