106

I would like to change the text size for some page part, e.g. for a verbatim block:

\begin{verbatim}
    <how to set the font size here to 10 pt? />
\end{verbatim}
0

5 Answers 5

132
\begingroup
    \fontsize{10pt}{12pt}\selectfont
    \begin{verbatim}  
        % how to set font size here to 10 px ?  
    \end{verbatim}  
\endgroup
1
  • 54
    The first parameter to fontsize is the font size to switch to and the second is the line spacing to use Feb 20, 2014 at 19:00
61

Example:

\Large\begin{verbatim}
   <how to set font size here to 10 px ? />
\end{verbatim}
\normalsize

\Large can be obviously substituted by one of:

\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge

If you need arbitrary font sizes:

3
  • 1
    Is there a way to provide exact size ?
    – jwaliszko
    Jul 10, 2010 at 18:30
  • 7
    Keep in mind that this goes against the spirit of LaTeX. Why do you want an exact size, anyway?
    – Arafangion
    Jul 13, 2010 at 10:46
  • 3
    @Arafangion, how can I get familiar with the spirit of it? I will appreciate if you provide some references Apr 8, 2018 at 11:57
14

The use of the package \usepackage{fancyvrb} allows the definition of the fontsize argument inside Verbatim:

\begin{Verbatim}[fontsize=\small]
print "Hello, World"
\end{Verbatim}

The fontsize that you can specify are the common

\tiny 
\scriptsize  
\footnotesize 
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
0
5

To add exact fontsize you can use following. Worked for me since in my case predefined ranges (Large, tiny) are not match with the font size required to me.

\fontsize{10}{12}\selectfont This is the text you need to be in 10px

More info: https://tug.org/TUGboat/tb33-3/tb105thurnherr.pdf

0
0

http://en.wikibooks.org/wiki/LaTeX/Formatting

use \alltt environment instead. Then set size using the same commands as outside verbatim environment.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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