7

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.

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

2 Answers 2

8

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

\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 TeX FAQ entry: Why doesn’t verbatim work within ...?

2

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}

result of MWE: test with “tabu*”

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .