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.
Best Answer
Add
\noexpand
before\hline
.