# Creating a multirow table entry with a variable number of rows

I wish to create a macro that receives a comma-separated list (clist) as an argument and returns a multirow table with the number of rows equal to the number of elements in the list.

I have defined a command \getNumItem that extracts the number of elements in a list. I wish to use the result as an input parameter for the number of rows in the command \multirow. However, this does not work (probably due to some expansion issues).

\documentclass{article}

\usepackage{xparse}
\usepackage{multirow}

\begin{document}

\ExplSyntaxOn

% Extract the number of elements in a clist
\DeclareExpandableDocumentCommand{\getNumItem}{m}{%

\int_new:N \numitem
\int_set:Nn \numitem {\clist_count:n{#1}}
\int_use:N \numitem
}

% Creates a multirow from a clist
\NewDocumentCommand{\secondCol}{m}{%

\tl_gclear_new:N \secondColRows

\clist_map_inline:nn {#1}{
\tl_gput_right:Nx \secondColRows {
& ##1 \exp_not:n {\\}
}
}
\tl_use:N \secondColRows
}
\ExplSyntaxOff

% Creates a multirow table with a number of rows equal to the length
% of the clist passed as arg #2
\newcommand{\multiRowTable}[2]{%
\begin{tabular}{|c|c|}
\hline
% This is what I would like to have
% \multirow{\getNumItem{#2}}{*}{#1} \secondCol{#2}

% This works
\multirow{2}{*}{#1} \secondCol{#2}
\hline
\end{tabular}
\\
% Verifying that \getNumItem{#2} works on its own
\getNumItem{#2}
}

% Test
\multiRowTable{a}{b,c}

\end{document}


I cannot figure out how to modify \getNumItem{#2} to make this work. Any help would be appreciated.

Based on your output, there is a simple solution - set a tabular with nested tabulars for the columns. Since tabulars are set by default to be vertically centred, there is no need for the number of rows to use in a \multirow setup.

\documentclass{article}

\usepackage{etoolbox}

\newcommand{\multiRowTable}[2]{%
\renewcommand{\do}[1]{##1 \\}%
\begin{tabular}{ | c | c | }
\hline
#1 & %
\begin{tabular}{ @{} c @{} }
\docsvlist{#2}
\end{tabular} \\
\hline
\end{tabular}
}

\begin{document}

\multiRowTable{a}{b,c}

\multiRowTable{a}{b,c,d}

\multiRowTable{a}{b,c,d,e}

\multiRowTable{a}{b,c,d,e,f}

\end{document}


etoolbox provides the list processing capability.