# Multicolumn verbatim

Is there someone who could help me with creating a table with some rows merged and verbatim text in it? I actually want to create 3x2 table. Like this

\begin{tabular}{rr}
\hline
\multicolumn{2}{c}{Verbatim text(in merged row)} \\
\hline
some text      & some text \\
\hline
verbatim number & verbatim number \\
\hline
\end{tabular}


I already tried to search here, but what I have found just brought me more errors. Thanks in advance.

• By "verbatim", are you referring to \verb-like commands? This is a known problem. If your "Verbatim text" contains no "special items", then you could just use \texttt. Nov 29 '11 at 20:30
• I mean \begin{verbatim} \end{verbatim} like enviroment. Nov 29 '11 at 20:48

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).
to show you some of the extended features of \texttt{fancyvrb}.

\bigskip

\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}