[Tex/LaTex] how fancyvrb background color fill completely with fillcolor

fancyvrbverbatim

I'd like the whole Verbatim (fancyvrb) block to have a background
color. How do I do it?

The fancyvrb package does define a fillcolor — but that only colors
the area around the margin — not the background of the block itself.

Best Answer

You can use tcolorbox with listings package seemlessly. There by one can combine the advantages and features of both. Here is an example.

\documentclass{article}
\usepackage{tcolorbox,listings}
\lstdefinestyle{mystyle}{
     basicstyle=\ttfamily,
     numbers=left, 
     numberstyle=\tiny, 
     numbersep=5pt     
 }
\tcbuselibrary{listings,skins,breakable}
\newtcblisting{BGVerbatim}{
      arc=0mm,
      top=0mm,
      bottom=0mm,
      left=3mm,
      right=0mm,
      width=\textwidth,
      boxrule=0.5pt,
      colback=yellow,
      spartan,
      listing only,
      listing options={style=mystyle},
      breakable
}

\begin{document}
\begin{BGVerbatim}
abc def {

xyz
\end{BGVerbatim}
\end{document}

enter image description here