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.

I'd like to make my code listing looking more sexy. I found a good example on SO, but one problem is remaining:

I would like to not only have a horizontal line at the bottom of the listing but also at the left and right side. Therefore I changed frame=b to frame = blr. This works fine, but the problem is now that there is a small gap between the vertical lines and the caption box. How can I correct this? I want a closed box with a caption around my listing.

share|improve this question
{looking-sexiy} may be nice, but {framed} is even better. ;-) –  lockstep Apr 5 '11 at 0:19
Yes, I thought it is time for a tag to indicate questions that want to make a latex document looking more sexy ;) –  RoflcoptrException Apr 5 '11 at 0:21

1 Answer 1

up vote 13 down vote accepted


\begin{lstlisting}[label=some-code,caption=Some Code]
public void here() {


enter image description here

share|improve this answer
Thanks but this is exactly the problem I have. If you look at the screenshot I made with your solution (img171.imageshack.us/img171/4317/testht.png) there is a gap between the vertical lines and the caption header. I wan't to remove this gap if possible. –  RoflcoptrException Apr 5 '11 at 7:11
@Herbert: it looks if I add the following \usepackage{calc} \newlength\tdima \newlength\tdimb \setlength\tdima{ \fboxsep+\fboxrule} \setlength\tdimb{-\fboxsep+\fboxrule} and then the listings options frame = tlrb, xleftmargin = \tdima, xrightmargin = \tdimb, if it works –  Danie Els Apr 5 '11 at 7:24
@Danie Els Thanks this works, but I has a line on the top that is not looking really nice. Can I remove it somehow? –  RoflcoptrException Apr 5 '11 at 7:51
@Roflcoptr: Make it the same color as the caption?, rulecolor= \color{gray}, –  Danie Els Apr 5 '11 at 9:11
@Danie Els but then all lines are this color? And where do I have to put this? –  RoflcoptrException Apr 5 '11 at 9:16

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.