8

With the package array, I want to define a new column type for my tables with the command

\newcolumntype{U}{>{\switchon}{l}<{\switchoff}}

However, the command I’d like to use is not a switch but a plain, unary macro like \emph or \textsc, so I must define \switchon such that

{\switchon some text}

will be equivalent to

\macro{some text}

(if it must be, I could live with \switchon some text \switchoff but I think this is not necessary.)

Converting a switch to a macro (e.g. \em to \emph) is pretty simple but how would I do it the other way round?

Edit

It seems, I also have to fight this problem which does not seem to allow for an explicit \switchoff (because I need to support the X column type of tabularx and it does not seem to work well together with newcolumntype):

\renewcommand{\tabularxcolumn}[1]{>{\theswitch}m{#1}}

Where \theswitch must be some (sensible) combination of \lowercase and other font macros. \lowercase has no ‘switch’ version (I think) which makes things a bit complicated.

Martin Scharrer
  • 262,582
Debilski
  • 1,341

2 Answers2

5

You can use the collcell package to feed the cell content to a macro:

\usepackage{collcell}

\newcolumntype{U}{>{\collectcell\macro}{l}<{\endcollectcell}}

Then \macro will receive the cell content as only argument, i.e. #1.


If the macro should be simply \emph or \textsc you can use the "switch" versions directly. For \emph it would be \em and for \textsc it is \scshape. See e.g. http://www.cl.cam.ac.uk/~rf10/pstex/latexcommands.htm for a table of such macros.

Martin Scharrer
  • 262,582
2

Define a macro like

\def\switchon#1\switchoff{\foo{#1}}

perhaps.

TH.
  • 62,639
  • I’m a bit ashamed of myself now, because I’ve already had this in the code but because a spurious \textnormal confused me, I did not notice it. Anyway, is it possible to have that without the explicit \switchoff? – Debilski Mar 28 '11 at 09:48
  • 1
    This wont work in the last column of array because the \switchoff is "hidden" by the \\. – Martin Scharrer Mar 28 '11 at 09:49
  • @Debilski: You need the \switchoff to mark the end of the argument. But you can hide it like the collcell commands in a \newcolumntype: \newcolumntype{V}{>{\switchon}l<{\switchoff}} – Ulrike Fischer Mar 28 '11 at 11:55
  • @Martin: Good point! – TH. Mar 29 '11 at 17:34