How to Define a Subscripted Unit in siunitx
At a glance
- 1. Declare the unit
Use DeclareSIUnit to define a command whose replacement contains the symbol and its subscript.
- 2. Format the symbol
Use text mode for upright letters; put the subscript in braces so it stays together.
- 3. Use the command
Pass the new command to qty or unit, just as you would a built-in unit.
To make a unit symbol with a subscript in siunitx, declare a custom unit and include the subscript in its definition. The example below defines the symbol “m” with the upright subscript “eff” and uses it after a number.
Minimal working example
\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\DeclareSIUnit{\meff}{\text{m}_{\text{eff}}}
\begin{document}
The measured value is \qty{3.2}{\meff}.
\end{document}
The output is a number followed by the unit symbol , with siunitx handling the spacing. The example uses the current siunitx command \qty. To print the unit without a number, use \unit{\meff}.
What the definition does
\DeclareSIUnit{\meff}{...} creates a unit command named \meff. The second argument supplies the printed symbol:
\text{m}prints the letter upright._{...}places the following material as a subscript.\text{eff}keeps the letters in the subscript upright, as is usual for a descriptive label.
The braces around eff make it a single subscript group. If the subscript is a mathematical variable that should be italic, write it as math instead—for example, \text{m}_{i}.
The example loads amsmath to provide \text. The siunitx package provides \DeclareSIUnit, \qty, and \unit.
Using the unit
Once declared, use \meff anywhere siunitx expects a unit:
\qty{3.2}{\meff} % a value and its unit
\unit{\meff} % the unit alone
For a document using the older siunitx interface, the corresponding value command is \SI{3.2}{\meff}. The custom declaration itself is the same. New documents should generally use \qty and \unit.
If the subscript contains more than one word or a longer expression, group it explicitly. For example:
\DeclareSIUnit{\mref}{\text{m}_{\text{ref}}}
Then use \qty{12}{\mref}. You can choose a command name that is clear in your source; it does not determine how the symbol is printed.
Common mistakes
- Putting the subscript outside the declaration: Writing
\unit{m}_{\text{eff}}leaves the subscript outside the unit argument. Define the full symbol as one unit instead. - Leaving the subscript ungrouped: In math syntax,
m_effmakes only the next character a subscript. Use braces for a multi-character label:m_{\text{eff}}. - Using a unit prefix as a subscript: Prefixes such as kilo- are handled by siunitx as part of unit parsing. A custom subscripted symbol is a distinct unit symbol and should be declared explicitly.
- Assuming the new symbol is an SI unit:
\DeclareSIUnitteaches siunitx how to typeset a command; it does not establish that the symbol is an officially defined SI unit. Use this for specialized or field-specific notation, and follow the conventions of your discipline.
If you need a compound unit with ordinary multiplication, division, or prefixes, keep those parts as separate siunitx unit tokens where possible. A custom symbol defined using text is treated as a single item, so siunitx cannot inspect or modify its internal subscript.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.