LaTeX forum ⇒ Math & Science ⇒ Units of measure

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Oldak
Posts: 4
Joined: Tue Apr 05, 2011 12:01 pm

Units of measure

Hi, I'm completely new to LaTeX (as of yesterday), but I've prepared a report in LaTeX, and it's working very well (thanks to Tobias Oetiker's The (Not So) Short Introduction to LaTeX2e).

I often need to use [number] [unit of measure] combinations such as: 32 mg kg^{-1} (i.e. 32 mg/kg ~matter of style preference). Which is the best practice to encode this?:

$32 mg kg^{-1}$
$32$ mg kg $^{-1}$
32 mg kg $^{-1}$

If the first option is preferable, should all symbols representing units of measure be done in math mode? Any justification for (or not for) using math mode to render units of measure?

Thanks to anyone who can help.
Last edited by Oldak on Wed Apr 06, 2011 5:44 pm, edited 1 time in total.

LaTeXguide.org • LaTeX-Cookbook.net

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Units of measure

By hand, I would go for
$$32$$\,mg\,kg$$^{-1}$$


using math mode for the mathematical content (using \mathrm for the units does work, but usually is over-kill). However, there are a number of more semantic approaches to the problem. I'd point to my own siunitx package, where the same effect as the above is available using
\SI{32}{mg.kg^{-1}}


or
\SI{32}{\mg\per\kg}


I prefer the later, more semantic, approach, for which you'll need to load abbreviated units
\usepackage[load-configurations = abbreviations]{siunitx}

Joseph Wright

Oldak
Posts: 4
Joined: Tue Apr 05, 2011 12:01 pm

Re: Units of measure

Great! Many thanks for your advice. I'll give your siunitx package a spin, it looks like it does what I need.

Oldak
Posts: 4
Joined: Tue Apr 05, 2011 12:01 pm

Re: Units of measure

I've been implementing siunitx for use with the report I am writing. I want to output "300–350g" (ndash, not hyphen). Using \SIrange{300}{350}{\gram}, the output is "300g to 350g". I've tried some quick hacks such as \SI{300}–{350}{\gram} which does output something similar to what I'm aiming for, except that the ndash is misaligned (the first number is followed by a small space). While skimming your documentation, I couldn't find a solution to this.

Is there an option for \SIrange to express the range using an ndash, with the unit following the end of the range (300–350g)?

P.S. \SI{3}{\gram\per\liter} results in "3 g L^{-1}". Is there an option to place a \cdot between "g" and "L" for the sake of clarity? Also, why does \litre result in "l" and \liter result in "L"? (I thought only "L" was acceptable.)
Last edited by Oldak on Wed Apr 06, 2011 5:48 pm, edited 1 time in total.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Units of measure

Oldak wrote:[…] While skimming your documentation, I couldn't find a solution to this.

Is there an option for \SIrange to express the range using an ndash, with the unit following the end of the range (300–350g)? […]

Actually the siunitx manual is quite clear in this regard. Searching the manual for „range“ with the search function of your PDF viewer gives you all necessary information, e. g. Table 16 and Table 23 (see code below}.
Oldak wrote:[…] \SI{3}{\gram\per\liter} results in "3 g L^{-1}". Is there an option to place a \cdot between "g" and "L" for the sake of clarity? […]

According to Section 5.10 of the manual this separator is also given by an option (see code below).
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{siunitx}
\usepackage{fix-cm}

\sisetup{%
inter-unit-separator=\cdot,
output-decimal-marker={.},
range-phrase={--},
range-units=single
}

\begin{document}
\SIrange{300}{350}{\g}

\SI{3}{\g\per\liter}
\end{document}

Oldak wrote:[…] Also, why does \litre result in "l" and \liter result in "L"? (I thought only "L" was acceptable.) […]

The according Wikipedia article has an explanation [1]. The German version of this article says that the „L“ has been introduced in order not to mix it up the „l“ with the digit „1“. Both symbols are accepted. I think the package just accommodates to that.

[1] Litre — Wikipedia, the free encyclopedia

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Oldak
Posts: 4
Joined: Tue Apr 05, 2011 12:01 pm

Units of measure

Many thanks localghost, the \sisetup example you give is exactly what I needed. It seems I could have read the documentation a bit more thoroughly.

Edit: Although if anyone intends to use localghost's example, replace "\cdot" with "{}\cdot{}", per the documentation advice (p38):

The standard setting is a thin space: another common choice is a centred dot. To get the correct spacing it is necessary to use {}\cdot{} in the later case.

Soraiaq
Posts: 1
Joined: Thu Jan 19, 2023 4:47 pm

Units of measure

Hello everyone,

I actually have a question according the \litre (l) - \liter (L) - situation.
I am using die SI-Unitx package in my report and needed to change the Liter-Character L to l. But despite the fact that I rewrite those spots from \liter to \litre I still get the L-Character as an output.
Am I doing something wrong or does LaTeX play games with me?

Melike

rais
Posts: 344
Joined: Sun Nov 16, 2014 8:51 pm

Units of measure

well, nowadays \liter is defined as
\DeclareSIUnit\liter{\litre}


so if you put
\DeclareSIUnit{\litre}{l}


into your preamble, you should get what you want---with \liter and \litre alike.
See section `Adjusting \litre and \liter' in siunitx documentation.

KR
Rainer