How can I set the space between a listing (lstlisting) and text that surrounds it? Is there a parameter I can set at the beginning of my document, that controls this? I tried framesep, but it just inflates the frame box.



\addvspace does what I need. How do I set this at the beginning of the document, so I don't have to add this manually to every listing?


I use listings like so:


Where cap and lbl are different captions/labels, so they are not constant for all listings.

  • Try \addvspace\medskipamount? Don't understand your question really well though. Or maybe a \vskip5pt. Is this a horizontal space or vertical space?
    – azetina
    Aug 26, 2012 at 19:42
  • @azetina: I updated my question.
    – qwe
    Aug 26, 2012 at 19:49
  • @qwe Why not make it into a \newenvironment or a \newcommand like \newcommand{\mylist}[1]{\addvspace\medskipamount \begin{lstlisting} {#1} \end{lstlisting}}
    – azetina
    Aug 26, 2012 at 19:49
  • listings provides aboveskip and belowskip, both of which are \medskipamount by default. You could increase this using \lstset{aboveskip=\bigskipamount, belowskip=\bigskipamount} in your document preamble.
    – Werner
    Aug 26, 2012 at 20:04
  • @Werner I didn't notice your comment while I was typing my answer.
    – lockstep
    Aug 26, 2012 at 20:12

2 Answers 2


Use the \lstset command and its aboveskip and belowskip keys. See section 4.3 of the manual for details.







\begin{lstlisting}[caption={A listing}]
(Listing contents)



You can use a \newcommand:

\addvspace\medskipamount %

Then use it in the form:

\myconfiguredlisting{content of listing goes in here}


  {\addvspace\medskipamount %

Then use the above as:

....... % lst content goes here.
  • I use lstlisting like so: \begin{lstlisting}[caption={cap},label=lbl] ... \end{lstlisting}. Your solution doesn't seem to handle parameters?
    – qwe
    Aug 26, 2012 at 19:58
  • I know that, just edit the solution as you please. I cannot update my answer thoroughly for now but I presume someone will post a more appropriate answer.
    – azetina
    Aug 26, 2012 at 20:01
  • Sorry for being imprecise, I edited my question yet again.
    – qwe
    Aug 26, 2012 at 20:05

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.