# Tag Info

8

Here is a way; I vastly prefer this to setting basewidth, because it doesn't box each character and doesn't need to guess whether the monospaced font uses half em character widths. \documentclass[a4paper]{report} \usepackage{listings} \begin{document} \lstset{ basicstyle=\ttfamily, columns=fullflexible, keepspaces=true, } \verb|basicstyle=\ttfamily, ...

6

AFAIK environment verbatim does not support the start of a line with a percent character as in the DTX file format. The following workaround can be done: The environment verbatim is written without the percent prefix: \begin{verbatim} \begin{exercise} Calculate $1 + 1 =$ \end{exercise} \end{verbatim} The inclusion in the files, generated by docstrip ...

6

The macros of the verbatimbox package can take things like \small as an optional argument. In this case, I chose the verbnobox environment, but there are others in that package than may better suit your need. \documentclass{article} \usepackage{verbatimbox} \begin{document} \noindent Normal Size \begin{verbnobox}[\small] 1 double x, y; 2 double z, w; ...

6

There is a case, where \null makes a difference: At the start of a line TeX removes glue and penalties. If \verb starts with an invisible space, then it would be removed: \documentclass{article} \begin{document} \noindent x\\ \begingroup % \let\null\relax \verb| |y \endgroup \end{document} \null as \hbox{} prevents that the space is gobbled ...

5

You appear to be using fancyvrb, which already has the feature you want: \documentclass{article} \usepackage{fancyvrb} \usepackage{lipsum} % just for the example \begin{document} \lipsum*[3] \begin{Verbatim}[fontsize=\small] 1 double x, y; 2 double z, w; 3 main(); 4 return 0; \end{Verbatim} \lipsum[3] \end{document}

4

For fancyvrb, you need to use \VerbatimEnvironment before the \begin{Verbatim}. That tells fancyvrb to detect the name of the current environment, and look for the end of that environment, rather than looking for a literal \end{Verbatim}. You will probably want to use a proper framing package to provide the background color...that way you won't have to ...

4

I would recommend the package listings, which is ment for this purpose. See the page on Wikibooks for simple explanations about settings and my MWE below: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{ % language=C++, % choose the language of the code numbers=left, % where to put the line-numbers ...

4

With the default setting fixed for columns, listings reserves 0.6em for characters; you need to adjust this to 0.5em using basewidth: \documentclass[a4paper]{report} \usepackage{listings} \lstset{ basicstyle=\ttfamily, columns=fixed, fontadjust=true, basewidth=0.5em } \begin{document} This is lstlisting: \begin{lstlisting} : paxos.learn ( addr n ...

3

One possibility using the listings package; since apparently you only want to highlight some specific strings, you can escape to LaTeX and do the coloring there (in my example I used the bera package just to have a mono-spaced font allowing boldface) \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{bera}% for boldfaced ...

3

As mentioned in Change typeface of verbatim environment, the default font used in verbatim is \ttfamily, as set in \verbatim@font. You can create a user interface to adjust this font in the following way: \documentclass{article} \usepackage{lipsum} % just for the example \makeatletter ...

3

pcr is the family name, it is used with \fontfamily, e.g.: \documentclass{article} \makeatletter \newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}% \makeatother \begin{document} \verbatimfont{\fontfamily{pcr}\selectfont} \begin{verbatim} This should be in pcr. \end{verbatim} \end{document} Or \documentclass{article} \makeatletter ...

2

Verbatim environments and macros in the verbatimbox package accept optional arguments that can change the font, font size, etc. \documentclass{article} \usepackage{verbatimbox} \begin{document} \begin{verbnobox}[\scriptsize] Testing scriptsize cmtt verbatim \end{verbnobox} \begin{verbnobox}[\fontfamily{pcr}\selectfont] Testing pcr verbatim \end{verbnobox} ...

2

Using fragile does not work for me when changing the mode as when generating slides and handouts from separate driver files calling the same content file so I came up with an ugly but effective work around. Let me give an example expanding on the one given above. The driver file to create slides is called contentfile.beamer and has the following: ...

1

First, here is a solution that uses only the xcolor package and the standard verbatim environment. But it is not a new environment, per se, and so does not directly answer the OP's question (for that, see below). \documentclass{article} \usepackage{xcolor} \fboxrule=1pt \begin{document} \setbox0=\hbox{\begin{minipage}{3in} \color{red!90} \begin{verbatim} ...

Only top voted, non community-wiki answers of a minimum length are eligible