2

I require a verbatim like environment that allows footnotes and, in addition, displays the footnote text in that environment (as opposed to the page) or just below the environment floating with it.

I have got the following.

\documentclass[a4paper,10pt]{book}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{bera}

\newenvironment{MyVerb}[1]
{\def\header{\S#1}\Verbatim[label=\header, frame=single, commandchars=@\{\}]}
{\endVerbatim}

\begin{document}

An apple a day....

\begin{MyVerb}{Blah}
 Blah.
 Blah@footnote{Blah.} blah.
 Blah.
\end{MyVerb}

...keeps the doctor away.

\end{document}

The footnote numbers appear but the footnote text appears neither on the page nor in the environment. I would like the footnote bodies to appear inside the "boxed" verbatim environment (as opposed to the page).

The footnotes need not be verbatim nor even appear directly in the verbatim environment itself, but they must appear at the bottom of the box around the verbatim.

3
+50

Two versions:

FOOTNOTE BELOW BOX

Putting it in a minipage seems to nearly satisfy the requirement, except the footnote is immediately below the box, not inside of it. I personally think this is how it should be. Note, however, that minipage footnote symbols are alphabetic, not numeric.

\documentclass[a4paper,10pt]{book}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{bera}

\newenvironment{MyVerb}[1]
{\def\header{\S#1}\Verbatim[label=\header, frame=single, commandchars=@\{\}]}
{\endVerbatim}

\begin{document}

An apple a day....

\bigskip\noindent\begin{minipage}{\textwidth}
\begin{MyVerb}{Blah}
 Blah.
 Blah@footnote{Blah.} blah.
 Blah.
\end{MyVerb}
\end{minipage}
\smallskip

...keeps the doctor away.
\end{document}

enter image description here

FOOTNOTE WITHIN BOX

Because this uses an \fbox, the border appearance can be changed with \fboxrule and \fboxsep.

\documentclass[a4paper,10pt]{book}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{bera}
\usepackage{xcolor,stackengine}
\newenvironment{MyVerb}[1]
{\par
\medskip
\noindent
\def\header{\textsf{\S#1}}%
\setbox0=\hbox\bgroup
\minipage{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}%
\Verbatim[commandchars=@\{\}]%
}{%
\endVerbatim
\endminipage%
\egroup
\stackengine{-\dimexpr.1pt+\fboxrule\relax}{\fbox{\copy0}}%
  {\fboxsep=-1pt\colorbox{white}{\,\,\,\header\,\,\,}}{O}{c}{F}{F}{S}%
\par
\bigskip}
\begin{document}
An apple a day....
\begin{MyVerb}{Blah}
 Blah. dsklfdkf dskljfd flk sdkfjl sdjfkldsfj
 Blah@footnote{Blah.} blah.
 Blah.
\end{MyVerb}
...keeps the doctor away.
\end{document}

enter image description here

  • much appreciated – fundagain Apr 3 at 19:07
  • @KJO Thank you. – fundagain Apr 3 at 19:07
  • 1
    @fundagain Made a small change, to prevent verbatim text from being covered up by white box of \header. – Steven B. Segletes Apr 3 at 19:09
  • Looks beautiful! – fundagain Apr 3 at 19:11

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.