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?

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

  • rounded or truncated ;-) – Marco Daniel May 10 '13 at 19:22
  • @MarcoDaniel Truncated: we want to see how many really fit. ;-) – egreg May 10 '13 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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