3

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}
1
  • Please, add the code you have up to now.
    – egreg
    Jul 24, 2012 at 9:42

1 Answer 1

3

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

1
  • 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? Aug 2, 2012 at 11:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .