Take the 2-minute tour ×
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.

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
add comment

1 Answer

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.

\documentclass{article}

\usepackage{tikz}
\usepackage{listings}


\begin{document}
\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} 
  };   
\end{document}
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
add comment

Your Answer

 
discard

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.