[texhax] [Suspected spam] Putting a border around verbatim text

Philip G. Ratcliffe philip.ratcliffe at uninsubria.it
Fri Aug 4 12:18:15 CEST 2006


> I've previously been shown how to treat my verbatim environments as
> floating by enclosing them in table environments, thus:
> 
> \renewcommand\tablename{Listing}
> 
> ...
> 
> \begin{table}[h]
> \begin{verbatim}
> .
> .
> .
> \end{verbatim}
> \caption{...}
> \label{...}
> \end{table}
> 
> This works fine but now I'd like to put a hairline border around the
> contents of the verbatim environment, not including the caption and also
> leave some padding between the border and content. Is this possible?

This is the best I can coe up with in less than 10 minutes:

\begin{table}[h]
\setlength\fboxsep{1em}% padding around content
\setbox0=\vbox{%
\begin{verbatim}
.
.
.
\end{verbatim}
\vspace*{-\baselineskip}
}
\fbox{\box0}
\caption{...}
\label{...}
\end{table}

Cheers,  Phil Ratcliffe


More information about the texhax mailing list