# Resize frame around Verbatim

The code:

 \begin{figure}
\begin{Verbatim}[frame=single,
framesep=5mm]
<pick ...>
<onMessage resolveByBPELEngine="true">
...
</onMessage>
...
</pick>
\end{Verbatim}
\caption{Pick Activity}~\label{fig:ResolvingPickActivity}
\end{figure}


How could I resize the width to make it fit to the code inside? It is ok for setting a value for let say a width attribute statically.

-

## 2 Answers

One way to do this is to use fancyvrb's saving mechanism and then place the material in an \fbox' appropriately defining the separation at that stage:

\documentclass{article}

\usepackage{fancyvrb}

\begin{document}

\begin{figure}
\centering
\begin{SaveVerbatim}{VerbCode}
<pick ...>
<onMessage resolveByBPELEngine="true">
...
</onMessage>
...
</pick>
\end{SaveVerbatim}
\setlength{\fboxsep}{5mm}
\fbox{\BUseVerbatim{VerbCode}}
\caption{Pick Activity}~\label{fig:ResolvingPickActivity}
\end{figure}

\end{document}


The SaveVerbatim environment saves the contents in the given name, here VerbCode. This is then reused with \BUseVerbatim.

-

The boxedverbatim-environment of the moreverb-package does exactly this. Here is an example:

\documentclass{article}
\usepackage{moreverb}

\begin{document}

\begin{figure}
\centering
\begin{boxedverbatim}
<pick ...>
<onMessage resolveByBPELEngine="true">
...
</onMessage>
...
</pick>
\end{boxedverbatim}
\caption{Pick Activity}~\label{fig:ResolvingPickActivity}
\end{figure}

\end{document}


Note: If you want more sophisticated formatting (with syntax coloring etc), take a look at the listings`-package (but no fitting of the box around the code, unfortunately)

-