This is a followup question from one asked by Andrew Howard. After some discussion, it became clear that colortbl has some issues with the names that can be used for a \newcolumntype. The result of the discussion digressed far enough that it seems like a new, more general, question may be asked.
Let's suppose that we want to define new columns without using \newcolumntype, which is limited in that names may only be a single character. The tabular environment can take more complex input. For example, without defining a \newcolumntype we can do this
\documentclass[10pt]{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{array}
\usepackage{colortbl}
\begin{document}
\begin{tabular}{|>{\columncolor{blue!10}}c|>{\columncolor{red!10}}c|}
Something & Something else\\
\end{tabular}
\end{document}
which is not particularly reusable. What we can't do is this
\newcommand{\colone}{>{\columncolor{blue!10}}c}
\newcommand{\coltwo}{>{\columncolor{red!10}}c}
\begin{tabular}{|\colone|\coltwo|}
Something & Something else\\
\end{tabular}
The array package provides \newcolumntype to get around this, but allows only single character names, which is not very satisfactory.
How can I force LaTeX to expand \colone and \coltwo before tabular gets them? Defining a new environment would be fine for this. In general how does one force expansion in a particular order using a new environment?
\newcolumntypeis provided byarray. Additionally, thearraypackage mentions (p 4 in thearraydocumentation) that "[it] takes care not to expand the [tabular/array] preamble", and therefore control sequences in the column specification does not work in the current scheme (it does without thearraypackage - the "old scheme"). – Werner Nov 14 '11 at 06:24It is clear that some of the issues can be mitigated with optional arguments to
newcolumntype. i.e.\newcolumntype{C}[1]{>{\columncolor{#1}}c}allows a simpler way to choose the colour and leave the rest the same.I'd still like to see some examples on how to apply
– qubyte Nov 14 '11 at 08:50expandafteron new environments.expandafterI was looking for, and it allows me to construct a new environment too. Feel free to put an answer in and I'll mark it as accepted. Otherwise I'll put one in tomorrow. – qubyte Nov 14 '11 at 15:35