Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I create, without a verbatim environment, these nice boxes that the Fancyvrb package produces:

Image from Fancyvrb

The sibling package Fancybox (by the same author) doesn't allow for the caption being placed onto the box's sides.

share|improve this question
    
I'd have a look at the package mdframed –  egreg Oct 10 '12 at 15:46
    
Wow! That's what I was looking for! Thanks! –  NVaughan Oct 10 '12 at 15:49
    
When you have a working solution, you can add a self-answer here. –  egreg Oct 10 '12 at 15:54
    
The second code in this answer tex.stackexchange.com/a/69154/3954 could be used as a starting point. –  Gonzalo Medina Oct 10 '12 at 17:32
    
Thanks, Gonzalo! That was very helpful indeed. –  NVaughan Oct 10 '12 at 19:33
show 3 more comments

1 Answer

up vote 5 down vote accepted

Using @GonzaloMedina's code (here), and @egreg's suggestion, the desired code is the following:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

\newenvironment{myenv}[1]
  {\mdfsetup{
    frametitle={\colorbox{white}{\space#1\space}},
    innertopmargin=0pt,
    frametitleaboveskip=-\ht\strutbox,
    frametitlealignment=\center
    }
  \begin{mdframed}%
  }
  {\end{mdframed}}

\begin{document}

\begin{myenv}{The frame title}
\lipsum[2]
\end{myenv}

\end{document}

It produces the following PDF (cropped here):

mdframed example

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.