8

I would like to determine how many characters of the verbatim font that fits on a text line. Consider:

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\noindent\hrulefill
\begin{Verbatim}[fontfamily=tt,fontsize=\small]
1234567890123456789012345678901234567890123456789012345678901234567890123456789012456789012345678901234567890123456789
\end{Verbatim}
\noindent\hrulefill\\
\end{document}

This gives me the following screenshot:

enter image description here

from which I can infer that there are approximately 73 characters on a line. How can I determine this number programmatically from within LaTeX?

Moriambar
  • 11,466

1 Answers1

9

Compute the number by dividing the text width by the width of one character:

\documentclass{article}
\newcommand{\computenumber}[1]{%
  Lines contain
  {\begingroup\count255=\textwidth
   \settowidth{\dimen0}{\ttfamily#1A}%
   \divide\count255 by\dimen0
   \number\count255\endgroup}
   characters in \texttt{\string#1}}

\begin{document}
\computenumber{\normalsize}

\computenumber{\small}

\computenumber{\footnotesize}
\end{document}

enter image description here

egreg
  • 1,121,712