13

I'm using listings to format blocks of code in my LaTeX, and I like it. But, except for large blocks of code, the border around the code block is bulky and breaks up the flow of how I read the document. I've tried searching around for a way to disable this code, but thus far I haven't found anything. Is it just impossible? Seems strange if this is the case.

12

Use the available options for the selected lstlisting environments; a litle example in which the style selected uses numbers to the left and a frame on the four sides of the listing; using frame=<valid values> and numbers=<valid values> one can change the behaviour for selected environments (for a list of all the keys and their <valid values> refer to the package documentation):

\documentclass{article}
\usepackage{listings}
\lstset{
  basicstyle=\small\ttfamily,
  frame=lrtb,
  numbers=left
}

\begin{document}

\begin{lstlisting}
test
\end{lstlisting}

\begin{lstlisting}[frame=none]
test
\end{lstlisting}

\begin{lstlisting}[frame=bt,numbers=none]
test
\end{lstlisting}

\end{document}

enter image description here

  • Awesome! Then as a follow-up question, is it possible to selectively enable borders, or otherwise specify options specific to a particular block? For example, if I normally didn't want to display line numbers, but I want to use them on some. – limp_chimp Oct 10 '12 at 1:53
  • 1
    @limp_chimp of course, see my updated answer. – Gonzalo Medina Oct 10 '12 at 2:02

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.