TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 8 down vote accepted

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

share|improve this answer

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*”

share|improve this answer
I would suggest writing up a minimal working example (MWE) using both tabu and fancyvrb to showcase its usage. It doesn't have to be complicated... – Werner Nov 30 '11 at 18:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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