Take the 2-minute tour ×
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.

I encounter an error when using the \verb command within the multicolumn command. I reduced the problem to the example below:

\documentclass{article}

\begin{document}
\begin{table}[htb]
\begin{center}
\begin{tabular}{c|c}
  \multicolumn{2}{c}{\verb+test+} 
\end{tabular}
\end{center}
\end{table}

\end{document}

Error message: \verb illegal in command argument

1. Why is using \verb not allowed within \multicolumn ?

2. How can I workaround this issue ?

share|improve this question
1  
Welcome to TeX.sx! –  hpesoj626 Oct 17 '12 at 8:32
1  
I believe that this question covers your problem (especially the answer by xport): tex.stackexchange.com/questions/24574/… Some more information is in answer by Werner here: tex.stackexchange.com/questions/33113/verb-in-custom-command –  tohecz Oct 17 '12 at 8:36

1 Answer 1

up vote 4 down vote accepted

You can use the package fancyvrb, I hope that the following example is self-explanatory (With credit to Werner):

\documentclass{article}
\usepackage{fancyvrb}% http://ctan.org/pkg/fancyvrb
\begin{document}
\DefineShortVerb{\#}% # denotes verbatim opening/closing character
\SaveVerb{VerbA}#test#

\begin{table}[htb]
\begin{center}
\begin{tabular}{c|c}
Row 1 & Row 1 \\
  \multicolumn{2}{c}{\UseVerb{VerbA}} \\
Row 3 & Row 3
\end{tabular}
\end{center}
\end{table}



\end{document}

The reasoning why you cannot use \verb in macro argument is a bit more complicated. As an argument, the \verb|test| is 1st read+stored in memory, and 2nd processed. While the command \verb needs to be proceesed at the same time as its read, basically because it has to remember the delimiter (| or # or whatever) and only then it can read the argument test.

(In real, it is more complicated and has to do with TeX inner mechanism of reading and interpreting its input, I only tried to give a short overview.)

share|improve this answer
    
Thank you very much for the explanation and the solution ! –  Ananke Leda Oct 17 '12 at 13:21

Your Answer

 
discard

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.