# One verbatim column in pgfplotstable and a non-verbatim header

I wanted to create a pgfplotstable in which one column would be treated as verbatim. I first tried to straightforwardly use \verb but I almost expected this to fail spectacularly and it did. I found Multicolumn verbatim but it was a different problem.

The best solution I found myself was to use \lstinline and collcell. The next big problem now was how to get the header back to normal since the cell content was verbatim after all.

I ran into a lot of other smaller problems with this table and I'm convinced there is a better solution than what I found, so I wanted to share this hoping it might help others and also to see if someone has a better solution.

So if you know a more elegant way to have a verbatim column with a non-verbatim header in pgfplotstable, I'll gladly accept it.

• The verbatimbox package is also good for getting verbatim into a table. It puts the verbatim text into a box (outside of the table), and the box can be recalled (typeset) inside the table. Jul 24 '13 at 1:10

First thing that eases up is the column property verb string type instead of string type. It will try its best to keep the special characters. But unfortunately backslashes and underscores are detokenized. So by postprocessing, we want to wrap the @cell content with a proper delimited macro either \lstinline or \verb or etc.

This is probably a design choice by Chrisitian Feuersanger for easing up prefixing control sequences to the @cell content but in fact ....../.add={\verb|}{|} would have been enough for the functionality. But unfortunately, it comes out as \verb | .... | and then verbatim delimiter is set to whitespace. So that's a bummer. It seems that every control sequence is separated with a whitespace. This probably saves us from lots of trouble but here it's working against us. I've also tried \csname verb\endcsname| but nope. Instead you can add the debug key and see that when those spaces are removed it really works without any problems.

If you have problems with the headers, just supress them and add manually. It's way easier than escaping them after 40 somersaults.

So I've removed a few things to make it clearer but I don't have any solution for the temporary change lst settings other than directly issuing at that particular entry.

\documentclass[a5paper]{article}
\usepackage{colortbl,pgfplotstable,listings}

\lstset{basicstyle=\ttfamily,breaklines=true,breakatwhitespace=true}
\pgfplotsset{compat=1.8}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\begin{table}%
\pgfplotstabletypeset[col sep=ampersand,row sep=\\,
every head row/.style={output empty row,before row={
}%
},
columns/Name/.style={verb string type,
column type=p{0.4\linewidth},
postproc cell content/.code={\edef\temp{\noexpand\lstinline\noexpand{##1}}%
\pgfkeyslet{/pgfplots/table/@cell content}{\temp}%
},
},
columns/Description/.style={column type=p{0.6\linewidth},string type},
every row no 3 column no 0/.style={postproc cell content/.append style={
},
]{
Name                                &Description\\
boring test                         &Shouldn't be problematic.\\
advanced token([0-9]*)_(.*)&Now this can really blow everything to pieces.\\
\multicolumn{1}{y{\halfacolumnwidth}}{{\lstinline[breakatwhitespace=false]|very-long-keyword_without_space|}}&For cosmetic reasons lines are only wrapped at spaces but sometimes this is not possible and we need an exception.\\
other advanced token([0-9]*)_(.*)&But this time we also have some inline code in this column: {\lstinline|'\\2' (0 = false, 1 = true)|}.\\
}
\end{document}


The same table produced with code that adopts ideas from percusse. Other than his code, this keeps the longtable stuff in:

\documentclass[a5paper]{article}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{pgfplotstable}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,breaklines=true,breakatwhitespace=true}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\newlength{\halfalinewidth}
\setlength{\halfalinewidth}{.5\linewidth}
\thispagestyle{empty}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\pgfplotstabletypeset[%
col sep=ampersand,
row sep=\\,
every head row/.style={output empty row, before row={
}%
},
columns/Name/.style={verb string type,
column type=p{\halfalinewidth},
postproc cell content/.code={\edef\temp{\noexpand\lstinline\noexpand{##1}}%
\pgfkeyslet{/pgfplots/table/@cell content}{\temp}%
},
},
columns/Description/.style={column type=L{\halfalinewidth},string type},
every row no 3 column no 0/.style={postproc cell content/.append style={
every last row/.style={after row=\caption[Test]{This is a test table. \texttt{verb} stuff is always a pain.}\\},
]{
Name&Description\\
boring test&Shouldn't be problematic.\\
flat_worm_test&The underscore causes a missing \\$ if \texttt{verb} isn't used.\\
advanced token([0-9]*)_(.*)&Now this can really blow everything to pieces.\\
very-long-keyword_without_space&For cosmetic reasons lines are only wrapped at spaces but sometimes this is not possible and we need an exception.\\
other advanced token([0-9]*)_(.*)&But this time we also have some inline code in this column: {\lstinline|'\\2' (0 = false, 1 = true)|}.\\
}
\end{document}


The result is exactly the same as the one already shown so no new image.

• @Jake You're very welcome :) But do you mean I should open a new question for each of the comparatively minor problems I solved? I'm not sure, I thought that to be overkill ... Jul 23 '13 at 19:29
• @Jake I see. I hope it's a bit clearer now, even though I still don't follow a strict question/answer scheme. Jul 23 '13 at 20:38