TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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} 

listing with margins

(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.

share|improve this question
up vote 6 down vote accepted

The space above and below the listing can be set using aboveskip and belowskip. The default value is \medskipamount.



\tikz \node[inner sep=1mm, text width=6cm, draw=green, line width=2pt, rounded corners]
    \lstinputlisting[basicstyle=\tiny\ttfamily, columns=fullflexible, breaklines=true,aboveskip=0pt,belowskip=0pt]{data.txt} 
share|improve this answer
That seems to solve most of the problem. There's still some small space left, although much narrower. Do you know how to get rid of it? – Little Bobby Tables Jan 18 '12 at 13:49
@LittleBobbyTables: Remove the inner sep=1mm from the \node option keys. – Daniel Jan 18 '12 at 15:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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