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.

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}
{label=\shellheader,frame=single}
share|improve this question
    
Please, add the code you have up to now. –  egreg Jul 24 '12 at 9:42
add comment

1 Answer

up vote 3 down vote accepted

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".

enter image description here

share|improve this answer
    
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
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.