Generate tabular data dynamically including `\hline`

foreachhlinetables

My question is same as this question but with this different that I need an \hline after every row in \tabledata. How can I do it?

Currently my code is as below:

\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\makeatletter
\newcommand{\myTable}[1]{%
    \def\tabledata{}% reset \tabledata
    \foreach \lhs/\rhs in {#1} {% build table data from #1  
        \protected@xappto\tabledata{\textbf{\lhs} & \rhs \\}
    }%
    \begin{tabular}{p{0.35\textwidth}|p{0.65\textwidth}}
        \hline
        Headline 1 & Headline 2 \\ \hline
        \tabledata \hline
    \end{tabular}
}
\makeatother

\begin{document}
   \myTable{{Title 1}/{Description 1}, {Title 2}/{Description 2}}
\end{document}

If I add \hline simply:

\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\makeatletter
\newcommand{\myTable}[1]{%
    \def\tabledata{}% reset \tabledata
    \foreach \lhs/\rhs in {#1} {% build table data from #1  
        \protected@xappto\tabledata{\textbf{\lhs} & \rhs \\ \hline}
    }%
    \begin{tabular}{p{0.35\textwidth}|p{0.65\textwidth}}
        \hline
        Headline 1 & Headline 2 \\ \hline
        \tabledata \hline
    \end{tabular}
}
\makeatother

\begin{document}
   \myTable{{Title 1}/{Description 1}, {Title 2}/{Description 2}}
\end{document}

Error:

Missing control sequence inserted.

Log File:

<inserted text> 
                \inaccessible 
l.19 ...Description 1}, {Title 2}/{Description 2}}
                                                  
Please don't say `\def cs{...}', say `\def\cs{...}'.
I've inserted an inaccessible control sequence so that your
definition will be completed without mixing me up too badly.
You can recover graciously from this error, if you're
careful; see exercise 27.2 in The TeXbook.

And also it produces following result:
enter image description here

Best Answer

Add \noexpand before \hline.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\makeatletter
\newcommand{\myTable}[1]{%
    \def\tabledata{}% reset \tabledata
    \foreach \lhs/\rhs in {#1} {% build table data from #1  
        \protected@xappto\tabledata{\textbf{\lhs} & \rhs \\\noexpand\hline}
    }%
    \begin{tabular}{p{0.35\textwidth}|p{0.65\textwidth}}
        \hline
        Headline 1 & Headline 2 \\ \hline
        \tabledata %\hline %don't need
    \end{tabular}
}
\makeatother

\begin{document}
   \myTable{{Title 1}/{Description 1}, {Title 2}/{Description 2},{Title 3}/{Description 3}}
\end{document}

enter image description here

Related Question