When using the lstlisting
environment, or similar ones from the listings
package, there are paragraph-like margins above and below the actual text. This makes sense in a paper, but gets in the way if you try to put code inside a Tikz node (e.g., for a Beamer presentation):
\node[inner sep=1mm, text width=6cm, draw=green, line width=2pt, rounded corners]
{%
\lstinputlisting[basicstyle=\tiny\ttfamily, columns=fullflexible]{alt1.java}
};
(Do ignore the question of why I put this jumbled code in a node…)
As you can see there are top and bottom margins that add extra redundant space to the node.
How can I remove these margins? I suppose it is some lstset
option, but I couldn't find it.
Best Answer
The space above and below the listing can be set using
aboveskip
andbelowskip
. The default value is\medskipamount
.