4

In this question, we learn how to use the array package to have an array column in math-mode:

\newcolumntype{L}{>{$}l<{$}}

However, for a table of symbols (with units), it would be convenient if I could do the same with \si{...}. However, neither

\newcolumntype{U}{>{\si{}l<{}}}

nor

\newcolumntype{U}{>{\si\{}l<{\}}}

seem to work (I tried escaping the { in that version), when I try it with this table:

\begin{tabular}{U}
\newton\per\meter
\end{tabular}

I get the error

! Undefined control sequence.
\newton ->\ERROR
l.29 \newton
\per\meter
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

for every unit used. Is there a way to do this?

9

Currently, siunitx provides an s-type column for this purpose. In the future I am likely to deprecate that (in general units should be in column headers), but the collcell package can also be used to achieve the same effect

\documentclass{article}
\usepackage{siunitx}
\usepackage{collcell}
\begin{document}
\begin{tabular}{ls>{\collectcell\si}c<{\endcollectcell}}
1 & \newton & \newton \\
2 & \metre  & \metre  \\
\end{tabular}
\end{document}

This can all then be wrapped in a new column type if you want ...

  • Why would you deprecate that? I agree that numerical tables should have their units in the column header, but a table of specs or a table of symbols such as often found in theses is definitely a valid use case for the s column. – Sanchises Dec 21 '17 at 16:37
  • @Sanchises Largely because it can be covered using collcell with no issues – Joseph Wright Dec 21 '17 at 16:38
5

That column type already exists, it is called

 s

You cannot pickup arguments from columns like you attempt, there you'll need sneaky tricks or use a package (who's name eludes me) which can colle3ct the contents of each cell in a column and give them to a macro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.