4 Answers
4

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.

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.

In other cases , we can use \cprotect to make \verb works. But this method seems not to work...
– SyvshcJan 31 at 14:09

@Syvshc The package says “Include \verb anywhere!”, but it should say almost anywhere; the problem here is that \multicolmust come first in a cell: either at the immediate beginning of a row or just after & (spaces are ignored). Using \cprotect\multicolumn defeats this.
– egregJan 31 at 15:29

The newverbs package also provides a \collectverb{<code>}<char><verbatim><char> macro which collects the verbatim for you and feeds it to a macro. However, \collectverb{\multicolumn{2}{c|}}|\sffamily| does not work here as \collectverb is not allowed between tabular rows (! Misplaced \omit.).