I need to deal with loads of code lines in verbatim mode and append them to the appendix. That is, I may not need to show them in a fancy way but I want them to occupy least amount of space. As you could see in the following figure, the text occupy a lot of space. I also need them to have a fix indent from right and left, so by keeping as many in a line, they indentation varies.

Asked
Active
Viewed 686 times
0
Paul Gessler
- 29,607
Ramin
- 291
2 Answers
2
Would this be close to what you seek? The proposed solution utilizes fancyvrb package where
xleftmargin/xrightmarin (dimension)commands for indentation to add at the start/end of each line (Default: 0pt—no left/right margin) is readily available.However, this solution also defines
myindentmacro taking one length argument for manual indentation withinVerbatimenvironment.Furthermore, the shrinking of text is via
resizeboxfromgraphicx. The outer frame can be removed by removing theframe=singlekey.

Code
\documentclass{article}
\usepackage[top=1cm]{geometry}
\usepackage{fancyvrb,graphicx}
\newcommand\myindent[1]{
\makebox[#1]{}
}
\begin{document}
Before:
\begin{Verbatim}[frame=single]
pred3(s11,s17,s11,s19,s10).
\myindent{1cm} pred3(s11,s17,s11,s19,s10).
\myindent{2cm} pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred4(s19).
pred5(s16).
pred6(s10,s12,s17,s11,s14).
logic symbols like ->
\end{Verbatim}
After:
\begin{Verbatim}[frame=single,commandchars=\\\{\}, xleftmargin=1cm,xrightmargin=1cm]
\resizebox{\textwidth}{!}{
\begin{minipage}{\textwidth}
pred3(s11,s17,s11,s19,s10).
\myindent{1cm} pred3(s11,s17,s11,s19,s10).
\myindent{2cm} pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred4(s19).
pred5(s15).
pred6(s10,s12,s17,s11,s14).
logic symbols like ->
\end{minipage}
}
\end{Verbatim}
\end{document}
Jesse
- 29,686
-
+1 (and I also borrowed your example to save typing the data:-) – David Carlisle Jul 03 '14 at 19:55
1
Please always provide a complete example document, Thanks to Jesse, I stole this one from the other answer.
You can use \small or any other font size to reduce the size of the verbatim:

\documentclass{article}
\begin{document}
\vspace*{-3cm}
Before:
\begin{verbatim}
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred4(s19).
pred5(s16).
pred6(s10,s12,s17,s11,s14).
logic symbols like ->
\end{verbatim}
After:
{\small
\begin{verbatim}
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred3(s11,s17,s11,s19,s10).
pred4(s19).
pred5(s16).
pred6(s10,s12,s17,s11,s14).
logic symbols like ->
\end{verbatim}}
\end{document}
David Carlisle
- 757,742
listingsinstead of the plainverbatimenv – daleif Jul 03 '14 at 14:24\lstset{basicstyle=\small\ttfamily,columns=fixed}and it is the same (more or less) asverbatim– daleif Jul 03 '14 at 14:38\smallbeforebegin{verbatim}– David Carlisle Jul 03 '14 at 15:21