Skip to content

Instantly share code, notes, and snippets.

@robotarmy
Created July 25, 2012 18:42
Show Gist options
  • Save robotarmy/3177813 to your computer and use it in GitHub Desktop.
Save robotarmy/3177813 to your computer and use it in GitHub Desktop.
How to layout code listings with a caption and a frame around the code
\usepackage{color}
\usepackage{xcolor}
\usepackage{calc}
\newlength\captionLeftDimension
\newlength\captionRightDimension
\setlength\captionLeftDimension{ \fboxsep+(\fboxrule*3)}
\setlength\captionRightDimension{-\fboxsep+(\fboxrule*3)}
\usepackage{listings}
\lstset{frame=single,
frameround=fttf,
xleftmargin=\captionLeftDimension,
rulecolor=\color{gray},
xrightmargin=\captionRightDimension}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip+1pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment