# How to add \hline to macro expansion?

I want to add one \hline to the macro expansion of this code, that is minimally modified version of David Carlisle's answer to Generating LaTeX tabular code during compilation.

Compiling this with latexmk -pdf main.tex gives a nice tabular. I was able to add \hline to the macro expansion of the macro that generates most of the rows by adding \def\hardline{\hline} and \expandafter\hardline in \def\xlistbody in g_orig_dest_tabular1_def.tex. I was also able to add \hline in the beginning of the code by adding \noexpand\hline in \def\tablestart in the same file. But I was not able to find out how I could generate \hline between first and second row of this tabular array. It must be in \def\listheadings or in \def\xlistheadings in g_orig_dest_tabular1_def.tex. So how \hline could be added to the macro expansion that is used to create the first row of this tabular array?

Thank you :)

main.tex:

\documentclass[12pt]{article}

\usepackage[american]{babel}
\usepackage{graphicx}

\input{g_orig_dest_tabular1_def}

\begin{document}

\input{g_orig_dest_tabular1}

\end{document}


g_orig_dest_tabular1_def.tex:

\newcommand\connorigdestregionlist{ABC,DEF,GHI}

% hardline.
\def\hardline{\hline}

\ifx\relax#1%
\expandafter\\
\else
&\textbf{#1}%
\fi}

% listbody.
\def\listbody{%
\expandafter\xlistbody\connorigdestregionlist,\relax,}

% xlistbody.
\def\xlistbody#1,{%
\ifx\relax#1%
\else
\textbf{#1}%
\gdef\thisrow{#1}%
\expandafter\xlistdata\connorigdestregionlist,\relax,%
\expandafter\hardline
\expandafter\xlistbody
\fi}

% xlistdata.
\def\xlistdata#1,{%
\ifx\relax#1%
\expandafter\\
\else
&\csname CONNorig\thisrow dest#1\endcsname
\expandafter\xlistdata
\fi}

% preamble.
\def\preamble{\expandafter\xpreamble\connorigdestregionlist,\relax,}
\def\xpreamble#1,{%
\ifx\relax#1%
\else
c%
\expandafter\xpreamble
\fi}

% tablestart.
\def\tablestart{%
\edef\temp{\noexpand\begin{tabular}{c\preamble}\noexpand\hline}%
\temp}


g_orig_dest_tabular1.tex:

\input{g_orig_dest_conn_def}

\tiny
\begin{table}
\scalebox{0.6}{
\tablestart
\listbody
\end{tabular}
} % end scalebox
\caption{Caption goes here.}
\begin{enumerate}
\item Item number one.
\item Item number two.
\end{enumerate}
\end{table}
\normalsize


g_orig_dest_conn_def.tex:

\def\CONNorigABCdestABC{ NA }
\def\CONNorigABCdestDEF{ from ABC to DEF }
\def\CONNorigABCdestGHI{ from ABC to GHI }

\def\CONNorigDEFdestABC{ from DEF to ABC }
\def\CONNorigDEFdestDEF{ NA }
\def\CONNorigDEFdestGHI{ from DEF to GHI }

\def\CONNorigGHIdestABC{ from GHI to ABC }
\def\CONNorigGHIdestDEF{ from GHI to DEF }
\def\CONNorigGHIdestGHI{ NA }

-
maybe I don't understand, but don't you just want \hline after the call to \listheadings as in the original answer? – David Carlisle Apr 20 '12 at 11:35
Does the following definition do the job: \def\xlistheadings#1,{% \ifx\relax#1% \expandafter\\\hline \else &\textbf{#1}% \expandafter\xlistheadings \fi} – Marco Daniel Apr 20 '12 at 13:06
@David Carlisle: Yes, but then as I have to create several different tabular arrays using slightly modified versions of this code, I thought that it would be easier to use, modify and maintain if all the code to create a tabular array of this kind was created by using only \tablestart \listheadings \listbody. – nrz Apr 20 '12 at 14:12
@Marco Daniel: It is exactly what I was looking for. Thank you. – nrz Apr 20 '12 at 14:14
well if all your arrays need a line after the heading just add \hline as the last thing in the definition of \listheadings – David Carlisle Apr 20 '12 at 14:16

To get a hline you can change the command \xlistheadings or \listheadings

The modification of \xlistheadings:

\def\xlistheadings#1,{%
\ifx\relax#1%
\expandafter\\\hline
\else &\textbf{#1}%

The modification of \listheadings
\def\listheadings{%