# Applying a function to column of table

I got Bruno's solution to work but now xcolor bizarrely gives me 'TeX capacity exceeded' when I use \rowcolors:

\documentclass{article}
\usepackage{ltablex,colortbl}
\usepackage[table]{xcolor}
\keepXColumns
\makeatletter
\def\KWP@safe@newline{%
\iffalse{\fi
\let\KWP@old@newline\\%
\let\\\cr
\iffalse}\fi
}
\def\KWP@restore@newline{\iffalse{\fi\let\\\KWP@old@newline\iffalse}\fi}

\newcolumntype{\arg}[1]{%
>{\KWP@safe@newline
#1{\ignorespaces \@sharp\unskip}%
\KWP@restore@newline
\span\@gobbletwo}%
m{3cm}%
}
\newcolumntype{\argmulti}[1]{%
>{\KWP@safe@newline
#1{\ignorespaces \@sharp\unskip}%
\KWP@restore@newline
\@gobbletwo}%
c%
}
\makeatother
% A simple test function:
\newcommand{\macro}[1]{\textcolor{red}{#1}}

\begin{document}
\arrayrulecolor{orange}
\rowcolors[\hline]{1}{yellow!25}{gray!25}
\begin{tabularx}{\linewidth}{|\arg{\macro}|m{2.5cm}|X|}
%\noalign{\hrule}
\hline
aaa & bbb & AAA \\\hline
fff & ggg & FFF\\\hline
hhh & \multicolumn{2}{|\argmulti{\macro}|}{HHH}\\\hline
\end{tabularx}
\end{document}


The 'capacity exceeded' problem seems to have come from tabularx. tabular compiles without trouble.

-

You haven't described what you are trying to achieve, nor why the code in the other question is not good for your purposes. I'm assuming that the question is "Why doesn't the code compile?"

• There is no \documentclass in your code snippet, not \begin{document} and \end{document};
• \textcolor requires a package (for instance \usepackage{color}, but it has probably been superseeded by other packages);
• when defining macros with @ in their names, they need to be placed between \makeatletter and \makeatother;
• you omitted two definitions, \KWP@safe@newline and \KWP@restore@newline;
• and \ang should be \arg in the preamble of the tabular.

With these changes,

\documentclass{article}
\usepackage{ltablex}
\usepackage{color}
\keepXColumns
\makeatletter
\def\KWP@safe@newline{%
\iffalse{\fi
\let\KWP@old@newline\\%
\let\\\cr
\iffalse}\fi
}
\def\KWP@restore@newline{\iffalse{\fi\let\\\KWP@old@newline\iffalse}\fi}

\newcolumntype{\arg}[1]{%
>{\KWP@safe@newline
#1{\ignorespaces \@sharp\unskip}%
\KWP@restore@newline
\span\@gobbletwo}%
m{3cm}%
}
\newcolumntype{\argmulti}[1]{%
>{\KWP@safe@newline
#1{\ignorespaces \@sharp\unskip}%
\KWP@restore@newline
\@gobbletwo}%
c%
}
\makeatother
\newcommand{\macro}[1]{\textcolor{red}{#1}}

\begin{document}
\hsize.5\hsize\noindent
\begin{tabularx}{\linewidth}{|\arg{\macro}|m{2.5cm}|X|}
aaa & bbb & AAA \\
fff & ggg & FFF\\
% hhh & \multicolumn{2}{|\argmulti{\macro}|}{HHH}\\
\end{tabularx}
\end{document}


On a side note, getting the whole column to be red can be done with >{\color{red}}c in the preamble.

-
@Bruno: I assumed you were familiar with all the needed prelims. That was why I didn't include them. Anyway, did it actually compile on your system? I keep getting Illegal pream-token ( ): c' used. –  Ahmed Musa May 1 '11 at 7:00
@Ahmed: this doesn't perclude writing a minimal working example and describing what you want to achieve. --- I just copied and pasted the code above in a fresh file, compiled with pdflatex. Can you give the result of \listfiles? –  Bruno Le Floch May 1 '11 at 7:25
Since the \enddocument is not reached, I had to call \@dofilelist instead. File List: article.cls, size10.clo, trace.sty, ltablex.sty, longtable.sty, tabularx.sty, array.sty, color.sty, color.cfg, dvips.def –  Ahmed Musa May 1 '11 at 8:53
@Ahmed. What really matters in the file list is the version of each file. Perhaps try to replace the X column by c, \begin{tabularx}{\linewidth} by \begin{tabular}, and \end{tabularx} by \end{tabular}, also removing \keepXColumns? You can then replace ltablex.sty by array.sty, and see what happens. If it still breaks, try replacing the \arg{\macro} column by a c` column. etc. Get to a minimal broken example, and post it. We probably have slightly different version of a package. –  Bruno Le Floch May 1 '11 at 11:47
@Bruno: I am yet to change the document, but here is the full file list: article.cls (2007/10/19 v1.4h), size10.clo (2007/10/19 v1.4h), trace.sty (2003/04/30 v1.1c), ltablex.sty ( 1995/11/06 v1.0), longtable.sty (2004/02/01 v4.11), tabularx.sty (1999/01/07 v2.07), array.sty (2008/09/09 v2.4c), xcolor.sty (2007/01/21 v2.11), color.cfg (2007/01/18 v1.5), dvips.def (1999/02/16 v3.0i). –  Ahmed Musa May 1 '11 at 14:33