Multicolumn verbatim
Here is one option, using the verbdef
package. You define some verbatim content in a macro, and then use the macro wherever you need it.
\documentclass{article}
\usepackage{verbdef}% http://ctan.org/pkg/verbdef
\begin{document}
\verbdef{\verbtext}{Verbatim text (in merged row)}% Verbatim text
\verbdef{\verbnum}{verbatim number}% Verbatim number
\verbdef{\verbfancy}{@'#&%^}% Fancy verbatim
\begin{tabular}{rr}
\hline
\multicolumn{2}{c}{\verbtext} \\
\hline
some text & some text \\
\hline
\verbnum & \verbnum \\
\hline
\verbfancy & \verbfancy \\
\hline
\end{tabular}
\end{document}
Verbatim text, otherwise, cannot be supplied as-is as an argument to a macro. See the UK TeX FAQ entry: Why doesn’t verbatim work within ...?
Take a look at the package tabu
– in the manual there's an own (sub)section named “Inserting Verbatim material (fancyvrb)”. That mean’s , you need fancyvrb
, too, but this is IME not a disadvantage. (I myself have no experience with it.)
Here’s an example (partly stolen from the manual):
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{tabu}
\usepackage{xcolor}
\begin{document}
According to the manual you need \texttt{tabu*} (the starred version).
I've added \Verb[commandchars=\\\{\}]|{\color{red}{\textbackslash}color}|
to show you some of the extended features of \texttt{fancyvrb}.
\bigskip
\begin{tabu*} spread 0pt {|X[-1r]|X[-1l]|}
\tabucline-
This is a small\newline
\Verb[commandchars=/\{\}]+{/color{green}\Verbatim}+ insertion
&
\vspace{-\baselineskip} %needs to be placed here
\begin{Verbatim}[commandchars=/\{\}]
And this is a complete
{/color{blue}Verbatim} environment
\end{Verbatim}
\\
\tabucline-
\end{tabu*}
\bigskip
Outside of the tabular environment \Verb|commandchars=\\\{\}| works fine,
which makes the backslash the familiar activation character for macros,
but inside it conflicts with the redefinition of \Verb|\\| -- therefore
it is replaced by \texttt{/}. There seem to be some other caveats, too --
for the comment character see the manual.
\end{document}