Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to typset the following

\resizebox{0.95\textwidth}{!}{%
 \begin{verbatim}
  require( "lattice" )
  require( "grid" )
 \end{verbatim}
}

I have a lot more to add to this box, and it needs to be typset verbatim, but it gives me an error. Am i doing something wrong.

share|improve this question

4 Answers 4

up vote 8 down vote accepted

You can not use verbatim in the argument to another command.

\documentclass{article}
 \usepackage{graphicx}
\begin{document}
\newsavebox\myv

\begin{lrbox}{\myv}\begin{minipage}{\textwidth}
\begin{verbatim}
...
\end{verbatim}
\end{minipage}\end{lrbox}

\resizebox{0.95\textwidth}{!}{\usebox\myv}
\end{document}
share|improve this answer
    
this still gives a error, albeit a new one :). So I should put in everything i want into the lrbox and then typeset the document? –  Sam Dec 13 '12 at 15:50
3  
You should always include complete documents in the question. I just made a complete document in my answer, that should run without error, if yours does not there is a difference somewhere –  David Carlisle Dec 13 '12 at 16:00
    
i accept my mistake. But thank you for answering the question. I think this solves the problem. –  Sam Dec 13 '12 at 16:01

If what you want is to reduce the size of the font used in verbatim, you can use the fancyvrb package:

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}

\begin{Verbatim}[fontsize=\small]
This will be verbatim at \small size
\end{Verbatim}

\end{document}

If you also want to shift a bit the verbatim text, use also the key xleftmargin, for instance

\begin{Verbatim}[fontsize=\small,xleftmargin=\parindent]

If you say

\fvset{fontsize=\small,xleftmargin=\parindent}

all you need in the document is

\begin{Verbatim}

(but you can countermand the global settings by specifying other values in the optional argument).

share|improve this answer
\documentclass{article}
\usepackage{fancyvrb,graphicx}
\begin{document}

\begin{SaveVerbatim}{myVerb}
  require( "lattice" )
  require( "grid" )
\end{SaveVerbatim}
\resizebox{0.95\textwidth}{!}{\BUseVerbatim{myVerb}}%

\end{document} 
share|improve this answer
    
Your answer is much simpler, but i like the previous answer by David Carlisle, because it does not require me to use additional packages. I also think this solution is more generic. –  Sam Dec 21 '12 at 15:48

There is the verbatimbox package that puts verbatim in a box

\documentclass{article}
\usepackage{graphicx}
\usepackage{verbatimbox}
\begin{document}
 \begin{verbbox}
  require( "lattice" )
  require( "grid" )
 \end{verbbox}
\resizebox{0.95\textwidth}{!}{\theverbbox}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.