# Tables header row's: how to ignore the column type?

I have several column types defined using the array and collcell package. An example

\newcolumntype{N}{>{\collectcell\num}c<{\endcollectcell}}

This alleviates making tables a lot, and makes them more readable in the source file. Yet when I make a table with some header rows, I have to escape the column commands (the headers don't need to be inside the \num) using \multicolumn:

\begin{tabular}{NN}
\hline
\hline
1.234 & 2.345\\
....
\end{tabular}

is there a quicker way of doing this? Perhaps by redefining the column type mid-table, or having a command that will generate an escape row?

-
Perhaps An improved \rowstyle that takes the cell contents as an argument will help; you would use conditionals to (de)activate a specific column operation. –  Werner Jan 9 '12 at 21:47
You might exploit the table making features of the siunitx package, for numeric tables. –  egreg Jan 9 '12 at 21:56
@egreg yes, yet I'm using different commands than \num alone and I would like an approach that works for the other commands too. Good tip though! –  romeovs Jan 9 '12 at 22:21
@Werner not a bad idea. Can't come up with a way that doesn't use save boxes though. (I can't put a save box inside, say, a \num, or even a \textbf). –  romeovs Jan 9 '12 at 22:38

One way to do this is to use a switch that is enabled when the header is completed. This switch is checked to see if the column macros are to be applied. When the header is completed, a call to \EndTableHeader needs to be made.

In the test below, the N column type applies the color red to each cell, and the result of:

\begin{tabular}{NN}
\hline
\hline
1.234 & 2.345\\
\end{tabular}

is that header column is not typeset in red:

## Notes:

• The solution here used the \newtoggle from the etoolbox package, as I find that syntax more readable. This can be adapted to the numerous other options for evaluating conditionals.
• I initialized the toggle when it is defined. Can probably get away with this, but I prefer to initialize variables when defined.
• Both the begin and end of the table are set to reset the toggle. This to protect against any accident set/reset that may be applied outside of the table, and also allows for the case of header rows that may occur in the middle of a table.
• I am sure there unnecessary % at the end of the lines in the preamble, but I find it safer to just always add them in my preamble, rather than figure out if they are necessary

## Code:

\documentclass{article}
\usepackage{collcell}
\usepackage{xcolor}% only needed for testing
\usepackage{etoolbox}

% Redefine tabular to initialize \StartTableHeader at start and end
\let\OldTabular\tabular%
\let\OldEndTabular\endtabular%

% Define the column type:
\newcolumntype{N}{>{\collectcell\myColorCell}c<{\endcollectcell}}%

\begin{document}
\noindent
\begin{tabular}{NN}
\hline
\hline
1.234 & 2.345\\
\end{tabular}

\bigskip\noindent
Check again to make sure that settings are correct at start of table:

\noindent
\begin{tabular}{NN}
\hline