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

\multicolumn{2}{c}{Verbatim text(in merged row)} \\
some text      & some text \\
verbatim number & verbatim number \\

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.
    – Werner
    Nov 29 '11 at 20:30
  • I mean \begin{verbatim} \end{verbatim} like enviroment.
    – user974514
    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.

enter image description here

\usepackage{verbdef}% http://ctan.org/pkg/verbdef
\verbdef{\verbtext}{Verbatim text (in merged row)}% Verbatim text
\verbdef{\verbnum}{verbatim number}% Verbatim number
\verbdef{\verbfancy}{@'#&%^}% Fancy verbatim
  \multicolumn{2}{c}{\verbtext} \\
  some text  & some text \\
  \verbnum   & \verbnum \\
  \verbfancy & \verbfancy \\

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):





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


\begin{tabu*} spread 0pt {|X[-1r]|X[-1l]|}
This is a small\newline
\Verb[commandchars=/\{\}]+{/color{green}\Verbatim}+ insertion
\vspace{-\baselineskip} %needs to be placed here
And this is a complete
{/color{blue}Verbatim} environment


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.


result of MWE: test with “tabu*”


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.