Graphics, Figures & Tableslistings | Framed Code Sample in Document

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
treeface99
Posts: 2
Joined: Fri Apr 20, 2012 5:09 pm

listings | Framed Code Sample in Document

Post by treeface99 »

Hi all,

I have found a great configuration for displaying code samples which looks like this:

Code: Select all

\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
}
This code adds a solid line above and below the code sample. I would really like to remove these lines Or even better, replace them with a box surrounding the code.

Any ideas?

Many Thanks
Last edited by Stefan Kottwitz on Fri Apr 20, 2012 5:27 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

listings | Framed Code Sample in Document

Post by cgnieder »

treeface99 wrote:Any ideas?
Happily for you I happen to know where the command \lstset is from. Next time it would be really helpful if you'd posted a Infominimal working example, please!

(Edit: I just saw you mentioned the package in the title of the post. Sorry...)

Did you have a look in the documentation of listings? You'd find there section 4.11 Frames.

I quote the beginning of that section:
frame=<none|leftline|topline|bottomline|lines|single|shadowbox> [default:]none
draws either no frame, a single line on the left, at the top, at the bottom, at the top and bottom, a whole single frame, or a shadowbox. Note that fancyvrb supports the same frame types except shadowbox. The shadow color is rulesepcolor, see below.
frame=<subset of trblTRBL> [default:]ffff
The characters trblTRBL designate lines at the top and bottom of a listing and to lines on the right and left. Upper case characters are used to draw double rules. So frame=tlrb draws a single frame and frame=TL double lines at the top and on the left. Note that frames usually reside outside the listing’s space.
Regards
site moderator & package author
treeface99
Posts: 2
Joined: Fri Apr 20, 2012 5:09 pm

Re: listings | Framed Code Sample in Document

Post by treeface99 »

Brilliant!

Thanks very much. Much appreciated.
Post Reply