[Tex/LaTex] Change font size of the verbatim environment

fontsizeverbatim

I want to apply small fonts inside the Verbatim environment e.g.

{\small 
\begin{Verbatim}

1   double x, y;
2   double z, w;
3   main();
4   return 0;

\end{Verbatim}}

Before the command \small and after the closing braket } text has normal size, which is obvious but the font size should be small inside the brakets.

Why is this command not applied to the environment's contents?

Best Answer

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}

enter image description here

Related Question