6

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:Columns test

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}

I can't really figure it out. Please help me!

5

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

Just define your column as

\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}
\usepackage{collcell} % loads array
    \newcolumntype{M}{>{$} l <{$}}
    \newcolumntype{U}{>{$[\collectcell\si} l <{\endcollectcell]$}}

\begin{document}

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

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

enter image description here

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? :) – aloevgaard Jan 30 '15 at 13:49
  • @AndreasLøvgaard You're welcome. And, yes, collcell loads array, so you can avoid loading it yourself. – karlkoeller Jan 30 '15 at 13:52
  • 2
    The brackets [] usually mean abstract dimensions (say “lenght/time”); for units, parentheses () or, better, nothing should be used. – egreg Jan 30 '15 at 14:01
8
  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}

enter image description here

  • 2
    4. Variables that are physical quantities shouldn't have prescribed units; if the equation and values are dimensionally consistent, the equation holds. – Paul Gessler Jan 30 '15 at 12:30
  • 1
    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. – aloevgaard Jan 30 '15 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]? – daleif Jan 30 '15 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. – percusse Jan 30 '15 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? – sdaau Feb 17 '15 at 1:09
4

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}

\begin{equation}
R = \sqrt{Q \frac{t}{\pi b n_{\eff}}}
\end{equation}
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}

enter image description here

  • 1
    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. – Paul Gessler Jan 30 '15 at 14:16
1

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}%
        \settowidth{\labelwidth}{\textsf{\quad#1}}%
        \setlength{\leftmargin}{\labelwidth + \labelsep}
        \setlength{\parsep}{0\baselineskip}
    }}%
    {\end{list}}

        \begin{document}
\begin{table}
    \begin{equation}
R = \sqrt{Q \frac{t}{\pi b n_{\text{eff}}} }
    \end{equation}
Where:
    \begin{mathentry}{$n_{\text{eff}}$}
\item[R]                Radius for BNBO     [\si{\meter}]
\item[Q]                Extraction rate     [\si{\cubic\meter\per\second}]
\item[t]                Time frame for BNBO [\si{\second}]
\item[b]                Aquifer thickness   [\si{\meter}]
\item[n_{\text{eff}}]   Effective porosity
    \end{mathentry}
        \end{document}

With this approach the units given in brackets probably seems more natural as in table. enter image description here

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.