2

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?

  • Using \begin{Verbatim}[samepage=true], as described here, is an alternative which doesn't alter the spacing. I am still curious if one can configure BVerbatim accordingly. – Emit Taste Nov 5 '13 at 19:47
2

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.

  • I don't get the same vertical spacing in the end, neither with \endBVerbatim nor with an additional \par – Emit Taste Nov 5 '13 at 19:52
1

You can define a new environment using BVerbatim as a basis.

\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,%
}

\newenvironment{myBVerbatim}%
{\bigskip\VerbatimEnvironment
\begin{BVerbatim}}
{\end{BVerbatim}%
\bigskip}

\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. \\ Before using myBVerbatim

\begin{myBVerbatim}
foo
bar
\end{myBVerbatim}

After using myBVerbatim

\end{document}

Which results in:

myBVerbatim environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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