[Tex/LaTex] A verbatim column in tabular environment

tablesverbatim

I want to build a table with a column of verbatim, but I don't want to use \verb command for every line (too many rows), how should I do it? I tried to use array package to define new column type but unsuccessful, anyone can shed some light? An example of what I wanna achieve:

\documentclass{article}

\begin{document}
\begin{tabular}{l l}
\verb|some text here| & some text here \\
\verb|some text here| & some text here \\
\verb|some text here| & some text here \\
\end{tabular}
\end{document}
  • I need verbatim (instead of just begin{tabular}{>{\ttfamily}l<{\ttfamily}} as the first row contained many reserved characters.

Thank you!

Best Answer

Verbatim mode is really very special. In some cases one can use the & for delimiting an argument (see the collcell package), but with verbatim this becomes essentially impossible, because the & is not the cell delimiter any more as soon as verbatim mode is started.

The shortvrb package allows to say

\MakeShortVerb{\|}

thereby declaring that, from the point on, |...| is equivalent to \verb|...|. Of course you'll need \verb+...+ (or similar) if the verbatim text contains |.

Note however that this will make | illegal in math, but there's the substitute \vert (or better the pair \lvert and \rvert provided by amsmath) for it.

So the best you can have is

\documentclass{article}
\usepackage{shortvrb}

\MakeShortVerb{\|}

\begin{document}

\begin{tabular}{l l}
|some % text here| & some text here \\
|some $ text here| & some text here \\
|some { text here| & some text here \\
\end{tabular}

\end{document}

enter image description here

Related Question