# Unit column in table with square brackets and siunitx

The header might be a bit weird. But I would like to add a specified column type that is reserved to units.

For instance, take a look at the following working example:

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{array}
\newcolumntype{M}{>{$} l <{$}}

\begin{document}

\begin{align}
R &= \sqrt{Q\: \frac{t}{\pi\: b\: n_{eff}}}
\end{align}

Where:\\

\begin{tabular}{M |l l}
R & Radius for BNBO & $\left[\si{\meter}\right]$ \\
Q & Extraction rate & $\left[\si{\cubic\meter\per\second}\right]$ \\
t & Time frame for BNBO & $\left[\si{\second}\right]$ \\
b & Aquifer thickness & $\left[\si{\meter}\right]$ \\
n_{eff} & Effective porosity & $\left[\si{--}\right]$ \\
\end{tabular}
\end{document}


This should return this:

Now, what I would like to do, is to be free of writing all the stuff before and after the unit. This means that instead of writing

$\left[\si{\cubic\meter\per\second}\right]$


I would simply just write

\cubic\meter\per\second


as the only thing for the unit description of Q.

As you can see, I have already defined a column with respect to math, the column M. I have tried to do it in a similar way with units, which returned an error. The code I tried was

\newcolumntype{U}{>{$\left[\si{ l <}\right]$}}


Inserting U into the third column and deleting math and siunitx environment, like this

\begin{tabular}{M |l U}
R & Radius for BNBO & \meter \\
Q & Extraction rate & \cubic\meter\per\second \\
t & Time frame for BNBO & \si{\second \\
b & Aquifer thickness & meter \\
n_{eff} & Effective porosity & - \\
\end{tabular}


the following error occurs:

Package array Error: >{..} at wrong position: token ignored. \begin{tabular}{M |l U}


This can be done with the help of the collcell package (loads array).

\newcolumntype{U}{>{$[\collectcell\si} l <{\endcollectcell]$}}


and you're done.

MWE

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\newcolumntype{M}{>{$} l <{$}}
\newcolumntype{U}{>{$[\collectcell\si} l <{\endcollectcell]$}}

\begin{document}

$$R = \sqrt{Q\: \frac{t}{\pi\: b\: n_{eff}}}$$

Where:\bigskip

\begin{tabular}{M |l U}
R & Radius for BNBO & \meter\\
Q & Extraction rate & \cubic\meter\per\second\\
t & Time frame for BNBO & \second\\
b & Aquifer thickness & \meter\\
n_{\textit{eff}} & Effective porosity & -\\
\end{tabular}
\end{document}


Output

Notice that the right way to add some spacing is not \\ but something like \bigskip. Also, usign align when there is nothing to align is not the best choice, use equation instead.

If you really want, but I would avoid it, you can even add \left and \right

\newcolumntype{U}{>{$\left[\collectcell\si} l <{\endcollectcell\right]$}}

• Thank you so much! :) That works great! And then I can just avoid the array package, since collcell loads it anyway? :) Jan 30, 2015 at 13:49
• @AndreasLøvgaard You're welcome. And, yes, collcell loads array, so you can avoid loading it yourself. Jan 30, 2015 at 13:52
• The brackets [] usually mean abstract dimensions (say “lenght/time”); for units, parentheses () or, better, nothing should be used. Jan 30, 2015 at 14:01
1. Please unlearn your habit of using \left ... \right all over

2. Drop the [], they do nothing to the interpretation of that column

3. use the s column, and in that column just write say \meter

In code

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{array,booktabs}
\newcolumntype{M}{>{$} c <{$}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\begin{document}

\begin{tabular}{M l s } %|
\toprule
\mc{Variable} & Meaning & \mc{Unit} \\
\midrule
R & Radius for BNBO & \meter\\
Q & Extraction rate & \cubic\meter\per\second\\
t & Time frame for BNBO & \second\\
b & Aquifer thickness & \meter\\
n_{\textup{eff}} & Effective porosity & \mc{---} \\
\bottomrule
\end{tabular}
\end{document}


• 4. Variables that are physical quantities shouldn't have prescribed units; if the equation and values are dimensionally consistent, the equation holds. Jan 30, 2015 at 12:30
• Since I intend to use the column type with no headlines (e.g. Unit headline), I prefer the square brackets []. And I would really like new column type with that. But thank you for the tip of using s column. Jan 30, 2015 at 12:43
• I still think it is better for the reader. What if the person reading it does not know the meaning of [m]? Jan 30, 2015 at 12:46
• @AndreasLøvgaard Unnecessary cryptic writing. There is nothing wrong with a header line. Your Where: does not serve anything in your example in that regard also. Jan 30, 2015 at 13:44
• I just wanted to say thanks for this discussion; where I used to study, it was actually a formal convention that units should be put in square brackets [], which is how I came upon this question - so to me, it is not cryptic at all. @PaulGessler - no one disputes whether the equation will hold; but if I see the equation for the first time (and if I'm, say, slightly dumb), are you saying that it would be easier for me to understand the dimensional relationships by not having the units spelled out? Feb 17, 2015 at 1:09

You add no meaning with the units in brackets; in my opinion it's even wrong, as usually brackets denote abstract dimensions, such as “length·time–1” or “force·length”.

The s column type is what you're looking for. I also removed all \: spacing commands, which are wrong, and set “eff” in upright type.

Note also that Where:\bigskip would allow a page break after it.

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}

\newcolumntype{M}{>{$} l <{$}}
\newcommand{\eff}{\textrm{eff}}

\begin{document}

$$R = \sqrt{Q \frac{t}{\pi b n_{\eff}}}$$
Where:\\*[\bigskipamount]
\begin{tabular}{M l s}
R & Radius for BNBO & \meter\\
Q & Extraction rate & \cubic\meter\per\second\\
t & Time frame for BNBO & \second\\
b & Aquifer thickness & \meter\\
n_{\eff} & Effective porosity & \multicolumn{1}{c}{--}\\
\end{tabular}
\end{document}


• Voted, but I'll repeat my comment: Variables that are physical quantities shouldn't have prescribed units; if the equation and values are dimensionally consistent, the equation holds. Jan 30, 2015 at 14:16

To my test is more appropriate for explanation of variables of some equation to use list environment than table. For example something as follows:

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{siunitx}

\newcommand{\mathentrylabel}[1]{%
\makebox[\labelwidth][l]{\parbox[t]{\labelwidth}{%
\raggedleft$#1$:}
}}
\newenvironment{mathentry}[1]%
{\begin{list}{}{%
\renewcommand{\makelabel}{\mathentrylabel}%
\setlength{\leftmargin}{\labelwidth + \labelsep}
\setlength{\parsep}{0\baselineskip}
}}%
{\end{list}}

\begin{document}
\begin{table}
$$R = \sqrt{Q \frac{t}{\pi b n_{\text{eff}}} }$$
Where:
\begin{mathentry}{$n_{\text{eff}}$}