2

I have a tabularx-table with a lot of SI values. For this, I wanted to define a new column type u which places the contents of the column into a \SI{XXX}{cm} expression.

\newcolumntype{u}{>{\SI\begingroup}{X}<{\endgroup{cm}}}

Using this in a tabularx-table throws me an "Illegal pream token X" and "invalid-token-in-number" exception. Replacing X with c leaves me with only the "invalid-token"-exception. What can I do to make this work?

1

1 Answer 1

4

One way to do what you desire is to use the collcell package:

enter image description here

Code:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{collcell}

\newcommand{\MyCommand}[1]{\SI{#1}{cm}}

\newcolumntype{u}{>{\collectcell\MyCommand}{l}<{\endcollectcell}}

\begin{document}
\begin{tabular}{l u}
  \toprule
    1 inch  & 2.54 \\
    1 meter & 100  \\
  \bottomrule
\end{tabular}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .