So I am writing a book on Awk programming language, and I have enabled a single frame via \lstset{frame=single}. However, I would like the code within the snippet box to be further away from the frame border. Any ideas how to change the padding of the code within the snippet box? In HTML I'd just do padding: 5px, but I can't figure out how to do it in LaTeX.

  • 1
    Found it myself \lstset{framesep=10pt} Apr 30 '11 at 1:55
  • 1
    If you've found the solution, you can post and accept an answer to this question. Apr 30 '11 at 8:10

Found it myself, it's \lstset{framesep=10pt} and as przemoc suggests in the comments also do \lstset{xleftmargin=10pt,xrightmargin=10pt} to make sure margins don't go outside of margin space.

  • 2
    Unfortunately you are wrong here. :) It's not CSS padding equivalent, at least not fully compliant. framesep=X is visually like setting padding-top:X;padding-bottom:X while left and right padding is going over page margins, thus difference is quite substantial, but can be overlooked for small values. To fix it you have to set also xleftmargin=X,xrightmargin=X.
    – przemoc
    Jun 15 '11 at 8:18
  • @przemoc: How to adjust the top and bottom margins as framesep=<value> also modifies the vertical spacing?
    – xport
    Aug 8 '11 at 19:50
  • @xport: Listings package is pretty bad at styling, as things change depending on other settings. I'm not completely sure what you want to achieve, but beside framesep (which isn't useful for margins if you have frame != none and that's why I said about padding earlier) there are aboveskip and belowskip options, set by default to \medskipamount (6.0pt plus 2.0pt minus 2.0pt) that you probably should play with.
    – przemoc
    Aug 9 '11 at 18:13
  • 1
    When used with backgroundcolor this appears to be less like a padding and more like a margin, since the text still goes to the edge of the colored area. Nov 25 '19 at 16:12

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.