I'm trying to define a macro for table headers but unfortunately I'm far from a TeX expert. I should split a list that is delimited with ampersands, format the entries and concatenate it again with ampersands. Splitting the list works but I can't concatenate it with ampersands.
\documentclass{article}
\usepackage{xstring}
\newcommand{\DLbase}[1]% #1 = comma delimited keywords
{{\saveexpandmode\expandarg%
\StrCut{\noexpand#1}{&}\DLleft\DLright%
\loop% extract keywords from list
\StrCut{\DLright}{&}\DLnext\DLright%
\textbf\DLleft\DLsep%
\edef\DLleft{\DLnext}%
\if\DLright\relax\else\repeat%
\textbf{\DLleft}%
\restoreexpandmode}}
\newcommand{\tabhead}[1]{\def\DLsep{&}\DLbase{#1}\\}
\begin{document}
\begin{table}[ht]
\begin{center}
\caption{Command / Purposes}
\begin{tabular}{|p{0.3\textwidth}|p{0.6\textwidth}|}
\hline
\tabhead{Command & Purpose}
\hline
cd & change directory \\
rm & remove files
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
I copied most of the code from here and here.
How do I have to define \DLbase
and \DLsep
that this works?
tabular
. See An improved\rowstyle
that takes the cell contents as an argument for an example.