2

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

\lstset{frame=topline|bottomline}

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

\lstset{frame=topline}

It correctly kept top border removing all others.

Similarly, when I tried:

\lstset{frame=bottomline}

It correctly kept bottom border removing all others.

How can I combine two?

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

2 Answers 2

2

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

none,

leftline,

topline,

bottomline,

lines (top and bottom),

single for single frames,

shadowbox.

(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:

\lstset{frame=lines}

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:

\lstset{frame=tb}
0

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

\documentclass{article}
\usepackage{listings}

\begin{document}
\lstset{language=Pascal}

\begin{lstlisting}[frame=tb] 
  for i:=maxint to 0 do
  begin
    { do nothing } 
  end;
\end{lstlisting}
\end{document}

enter image description here

You must log in to answer this question.

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