Creating a box around a figure that includes the tabbing environment

11k views Asked by At

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!

1

There are 1 answers

0
Peter Grill On 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}