# How can I combine \seq_use:Nn and \seq_map_inline:Nn?

The following 'naïve' solution throws the error:

ERROR: Misplaced \omit.

--- TeX said ---
\multispan ->\omit
\@multispan
l.13   }
\\
--- HELP ---
From the .log file...

I expect to see \omit only after tab marks or the \cr of
an alignment. Proceed, and I'll ignore this case.

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn

\begin{document}

\seq_set_split:Nnn \l_tmpa_seq { , } { 1 , 2 , 3 }

\begin{tabular}{*{\seq_count:N \l_tmpa_seq}{c}}
hellow & world \\
\seq_map_inline:Nn \l_tmpa_seq {
\multicolumn{1}{|c|}{#1} &
} \\
goodbye & world
\end{tabular}
\end{document}


where I'd like to come up with a table like:

  hello    world
|   1    |   2   | 3 |
goodbye   world


-
Isn't this caused (as the help tells you) by an unequal number of items in each row? You have 2 cells in the first row, and then write a sequence of three cells to the second. Perhaps add an & to the first and last row? – hugovdberg Apr 3 '14 at 18:34
@hugovdberg The error message is clear, but you actually don't need an equal number of items in each row :) as long as you don't make more columns than you specify, you're ok. The question is more to get the result I'm going for, not necessarily to fix the code I have. I'm fairly certain my approach will turn out to be utterly fruitless :( – Sean Allred Apr 3 '14 at 18:35
and what about a newline after the \seq_map_inline and an extra & after the third item? You have 3 items, each with a & so specifying 4 cells in that row actually, while a count of the sequence returns 3. Perhaps a conditional if items < count insert &? – hugovdberg Apr 3 '14 at 18:37
@hugovdberg Ah yes, that's a typo :) see my edit – Sean Allred Apr 3 '14 at 18:39
It's a problem of expandability. \seq_map_inline:Nn is not expandable. You can use \seq_map_function:NN after defining a (non-protected) function which does \multicolumn{...}{...}{#1}. – Bruno Le Floch Apr 3 '14 at 21:02

You have to use an expandable function, because any unexpandable token makes \multicolumn illegal after it.

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn

\begin{document}

\seq_set_split:Nnn \l_tmpa_seq { , } { 1 , 2 , 3 }
\seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
{
& \multicolumn{1}{c|}{#1}
}

\begin{tabular}{*{\int_eval:n { \seq_count:N \l_tmpa_seq + 1 }}{c}}
hellow & world & some \\
\multicolumn{1}{|c|}{\l_tmpa_tl}
goodbye & world & again
\end{tabular}
\end{document}


Note that the first item should be detached because it needs a different treatment.

-