# How to set the Top Margin for a custom Verbatim environment (fancyvrb)

From the fancyvrb documentation, it looks like I can set left and right margins (paragraph 4.1.13) only. How can I set the top margin for my environment?

More specifically, given that I have a frame and a top title in my environment, I would like some extra padding between the top frame and the first line of text.

\newcommand{\shellheader}{This is a Shell}
\DefineVerbatimEnvironment{shell}{Verbatim}

-
Please, add the code you have up to now. – egreg Jul 24 '12 at 9:42

I propose a horrible hack that should take into account all your needs:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}

\DefineVerbatimEnvironment{shell}{Verbatim}{
commandchars=\%\{\},
label=\shelltitle,
frame=single,
formatcom=\setcounter{prompt}{0}\start
}
\newcommand{\shelltitle}{This is a shell}

\makeatletter
\def\start{\let\FV@FV@ProcessLine\FV@ProcessLine
\def\FV@ProcessLine{\noindent\vrule height3ex depth2ex
\hbox to\hsize{\kern\FV@FrameSep This is the shell prompt\hfil}%
\kern-.8pt\vrule\par
\let\FV@ProcessLine\FV@FV@ProcessLine
\FV@ProcessLine}%
}
\makeatother

\newcounter{prompt}
\newcommand{\prompt}{\stepcounter{prompt}\theprompt>}

\begin{document}
\begin{shell}
%prompt echo foo{}
foo
%prompt echo bar
bar
\end{shell}
\end{document}


Act on 3ex and 2ex for modifying the spacing before and after the fixed "This is the shell prompt".

-
Awesome. There's only one little detail left. I'm using the "samepage=true" option. This causes the actual shell content not to be broken, but it doesn't work for the header. Any way I can include the header line ("This is the shell prompt") in the "unbreakable" content? – Roberto Aloi Aug 2 '12 at 11:22