Creating a box around a figure that includes the tabbing environment

figureframelatextabbing

I would like to create a frame or box around my LaTeX figure, which consists of code formatted with the tabbing environment. My code looks something like this:

\begin{figure}
\begin{tabbing}
\texttt{void method(I, T, E)} \{ \\
\ \ \texttt{some code}<\emph{some pseudo code}>();\\
...
\end{tabbing}
\caption{The caption for the figure}
\end{figure}

I have tried using various box and frame commands, both within and without the figure, but LaTeX typically responds with "Something's wrong–perhaps a missing \item" or "Not in outer par mode".

How can I create a box around the contents of my figure?

Thanks!

Best Answer

One way is to use the mdframed package. It is quite customizable, I defined a style to illustrate its use:

enter image description here

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}

\mdfdefinestyle{mystyle}{
    backgroundcolor=yellow!20
}

\begin{document}
\begin{figure}
\begin{mdframed}[style=mystyle]
\begin{tabbing}
\texttt{void method(I, T, E)} \{ \\
\ \ \texttt{some code}<\emph{some pseudo code}>();\\
...
\end{tabbing}
\caption{The caption for the figure}
\end{mdframed}
\end{figure}
\end{document}
Related Topic