Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

enter image description here

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.

share|improve this question

2 Answers 2

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:

Sample output

\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.

share|improve this answer

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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