[Tex/LaTex] Verbatim has different margins than BVerbatim

spacingverbatim

I am changing some Verbatim blocks to BVerbatim to avoid page breaks in the middle of some short source code examples:

\documentclass[a4paper]{book}

\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage[scaled=.73]{beramono}
\fvset{baselinestretch=0.94}
\parindent=0pt
\parskip = 6pt
\lstset{
  basicstyle=\linespread{0.94}\ttfamily,%
  fancyvrb=true,%
}

\begin{document}

Before using Verbatim.

\begin{Verbatim}
foo
bar
\end{Verbatim}

After using Verbatim. \\ Before using BVerbatim.

\begin{BVerbatim}
foo
bar
\end{BVerbatim}

After using BVerbatim.

\end{document}

However, these two have different margin settings. BVerbatim has less spacing before and after the code block:

enter image description here

How can I adjust BVerbatim here so that it looks like Verbatim?

Best Answer

Verbatim uses an own paragraph for its contents, but BVerbatim not. You can use:

\usepackage{fancyvrb}
\RecustomVerbatimEnvironment{BVerbatim}{BVerbatim}{formatcom=\bigskip}

But there is no option to add vertical space at the end. You have to rewrite \endBVerbatim or to add \par.