You can use the package fancyvrb
, I hope that the following example is self-explanatory (With credit to Werner):
\documentclass{article}
\usepackage{fancyvrb}% http://ctan.org/pkg/fancyvrb
\begin{document}
\DefineShortVerb{\#}% # denotes verbatim opening/closing character
\SaveVerb{VerbA}#test#
\begin{table}[htb]
\begin{center}
\begin{tabular}{c|c}
Row 1 & Row 1 \\
\multicolumn{2}{c}{\UseVerb{VerbA}} \\
Row 3 & Row 3
\end{tabular}
\end{center}
\end{table}
\end{document}
The reasoning why you cannot use \verb
in macro argument is a bit more complicated. As an argument, the \verb|test|
is 1st read+stored in memory, and 2nd processed. While the command \verb
needs to be proceesed at the same time as its read, basically because it has to remember the delimiter (|
or #
or whatever) and only then it can read the argument test
.
(In real, it is more complicated and has to do with TeX inner mechanism of reading and interpreting its input, I only tried to give a short overview.)