I want to have border at top and bottom of my code. I tried setting it in lstset as follows:


However it simply removed right side border and kept all borders intact. When I tried:


It correctly kept top border removing all others.

Similarly, when I tried:


It correctly kept bottom border removing all others.

How can I combine two?

  • 1
    \lstset{frame=tb} should work. Or alternatively \lstset{frame=lines}.
    – leandriis
    Commented Sep 12, 2020 at 8:46

2 Answers 2


According to the documentation, the frame key accepts the following values:





lines (top and bottom),

single for single frames,


(See section "2.7 Layout elements" on page 18 of the listings documentation version 1.8d.)

In order to get a top and bottom line, you can thus use the built in lines key as follows:


In addition to the before mentioned, 7 predefined styles, you can also fine tune the lines around the listing by using a combination of t, l, r, and b for single lines or the upper case versions for double lines.

A single line above and below the listing would thus correspond to:


According to the manual (page 36) you have to specify multiple options with single characters:



  for i:=maxint to 0 do
    { do nothing } 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .