[Tex/LaTex] Teletype \textbackslash in alltt environment

verbatim

The alltt package provides a beefed up verbatim environment where \ and {} are not treated literally. A literal backslash can be inserted with \textbackslash, however, it does not have the same teletype font as the rest of the verbatim text. I tried some variataions such as \texttt{\textbackslash} but these don't seem to help. Any ideas how to insert a backslash (or curly braces) in teletype font when using alltt?

Best Answer

This has nothing to do with alltt. You need T1-encoding. Without it \textbackslash is taken from the symbol font. Check the difference:

\documentclass{article}
%\usepackage[T1]{fontenc}
\pagestyle{empty}
\begin{document}
\ttfamily \textbackslash abc
\end{document}
Related Question