# Verbatim frame latex with no waste

I have a frame/boarder round my Verbatim environment however the frame is extended to the page side, thus alot of wasted space. The following is my code:

    \begin{Verbatim}[frame=single]
s=0
for j = 1 : i -1
s = s + aij * akj
end
aki = (aki - s) / aii

\end{Verbatim}

-
I would like the frame to fit around the code. –  Joshua Feb 28 '14 at 9:19
Rather than clarifying in comments, please edit your question to include the information. A complete, compilable, minimal example would also be nice. –  Torbjørn T. Feb 28 '14 at 9:27
And minimal as in something we can copy and cimpile ourself without having to add anything. Where does Verbatim come from, which class is used .... –  daleif Feb 28 '14 at 9:37

The Verbatim environment from the fancyvrb has not an options to do that.

But you can use the similar environment boxedverbatim from the moreverb package. Remember anyway to eliminate the spaces at the beginning of lines.

MWE

\documentclass{article}
\usepackage{moreverb}

\begin{document}

\begin{boxedverbatim}
s=0
for j = 1 : i -1
s = s + aij * akj
end
aki = (aki - s) / aii
\end{boxedverbatim}

\end{document}


Output

-

If you wish to add spice to your verbatim later, here is an option with tcolorbox. This box can break across pages.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable}

\newtcblisting{myverbatim}{
arc=3mm,
top=0mm,
bottom=0mm,
left=0mm,
right=0mm,
boxrule=0.5pt,
colback=gray!30,
listing only,
hbox,
breakable
}

\begin{document}

\begin{myverbatim}
s=0
for j = 1 : i -1
s = s + aij * akj
end
aki = (aki - s) / aii
\end{myverbatim}

\end{document}


-

The verbatimbox package can also do this. The nice thing here is that the boxed content is not immidately printed, so that it can then be inserted anywhere a LaTeX box can go. Here it is inside an \fbox, but it can be placed inside a table, a footnote, a section title, etc.

There is also a different environment myverbbox in which you provide the name of the recalling macro (different than \theverbbox).

\documentclass{article}
\usepackage{verbatimbox}

\begin{document}

\begin{verbbox}
s=0
for j = 1 : i -1
s = s + aij * akj
end
aki = (aki - s) / aii
\end{verbbox}
\fbox{\theverbbox}

\end{document}


-