The earlier answers cover the standard approaches to a case like this: use \texttt
(either directly or through a new command), or somehow save the verbatim content in a normal context and then load it later.
Here is an alternate approach that uses fvextra
. This requires v1.4, the newest version. fvextra
now provides a \Verb
command (note capitalization) that works inside other commands under most circumstances, with a few limitations such as no #
or %
. Details about limitations are in the documentation.
\documentclass{article}
\usepackage{array}
\usepackage{fvextra}
\begin{document}
\begin{tabular}{|c|c|}\hline
\multicolumn{2}{c|}{\Verb|\sffamily|}
\end{tabular}
\end{document}
fvextra
now also provides a command \EscVerb
for the cases when \Verb
won't work inside another command. \EscVerb
is similar to \Verb
and the normal \verb
, except that the backslash serves as an escape character (\\
becomes \
, \#
becomes #
, etc.), and the argument must be delimited with a pair of curly braces.
\documentclass{article}
\usepackage{array}
\usepackage{fvextra}
\begin{document}
\begin{tabular}{|c|c|}\hline
\multicolumn{2}{c|}{\EscVerb{\\sffamily}}
\end{tabular}
\end{document}