# Interaction between \docsvlist and tabular

I'm trying to use \docsvlist from etoolbox to generate a table row. However, I've found a weird interaction when I try to use this trick to skip the first ampersand in the output. Here's an MWVE:

\documentclass{standalone}
\usepackage{etoolbox}

\begin{document}
\def\nextitem{\def\nextitem{&}}%
\renewcommand*{\do}[1]{\nextitem #1}%
\begin{tabular}{c|c|c|c|c}
\docsvlist{a,b,c,d,e}
\end{tabular}
\end{document}


When I compile this file, the table it produces looks like this:

I'd expect it to look more like this:

Interestingly, if I modify the separator to be something other than &, like ,, it works as would be expected:

And even more interestingly, if I change \def\nextitem{\def\nextitem{&}} to just \def\nextitem{&}, it works correctly, except that it has an extra blank cell at the beginning:

To me this suggests that there is some very specific problem with redefining \nextitem to & while inside the tabular environment. How can I fix this issue?

Each cell within a tabular forms a group. So your redefinition of \nextitem within the cell doesn't survive to the next cell. If you make the redefinition global - via \gdef (say) - you achieve the desired output:

\documentclass{article}

\usepackage{etoolbox}

\begin{document}

% Local \nextitem redefinition
\def\nextitem{\def\nextitem{&}}% http://tex.stackexchange.com/a/89187/5764
\renewcommand*{\do}[1]{\nextitem #1}%
\begin{tabular}{c|c|c|c|c}
\docsvlist{a,b,c,d,e}
\end{tabular}

% Global \nextitem redefinition
\def\nextitem{\gdef\nextitem{&}}% http://tex.stackexchange.com/a/89187/5764
\renewcommand*{\do}[1]{\nextitem #1}%
\begin{tabular}{c|c|c|c|c}
\docsvlist{a,b,c,d,e}
\end{tabular}

\end{document}