Units in LaTeX (siunitx)
Units are set upright with a thin space after the number, 9.81 m/s²; the siunitx package does this for you with \qty{number}{unit}, and \mathrm does it by hand.
LaTeX command
\qty{9.81}{\metre\per\second\squared}Not the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
Typing m/s inside maths gives italic m and s, which read as variables. By hand, write the unit upright with \mathrm and put a thin space, \,, before it: . That works everywhere, KaTeX included.
siunitx names each unit and prefix: \qty{9.81}{\metre\per\second\squared} prints 9.81 m s⁻², or 9.81 m/s² with the option per-mode=symbol. \unit gives a unit alone, \num a number alone, with \num{6.022e23} printing scientific notation, and \qtyrange{1}{5}{\metre} a range.
The current siunitx, version 3, uses \qty and \unit; older documents use \SI and \si, which still work. Percentages are \qty{50}{\percent}, and angles \ang{45}.
Numbers and units with siunitx
Load the package, then write a quantity, a unit, a number or a range. Each formats spacing, upright type and powers of ten the same way across the document.
\usepackage{siunitx}\qty{9.81}{\metre\per\second\squared}\num{6.022e23}\qtyrange{1}{5}{\metre}Other forms
\unit{\kilo\gram}a unit on its own\num{6.022e23}a number in scientific notation\qty{50}{\percent}a percentage\qtyrange{1}{5}{\metre}a range9.81\,\mathrm{m\,s^{-2}}by hand, no packageExamples
$9.81\,\mathrm{m\,s^{-2}}$acceleration, by hand
$v = 3.0 \times 10^{8}\,\mathrm{m/s}$the speed of light
$E = 4.2\,\mathrm{kJ}$a prefix and unit, upright
$T = 300\,\mathrm{K}$kelvin, with no degree sign
$\rho = 1000\,\mathrm{kg\,m^{-3}}$a density
Tips and common mistakes
- Set units upright, with
\mathrmor siunitx; italic letters read as variables. - Put a thin space,
\,, between the number and the unit. - Use
\qtyand\unitin new documents;\SIand\siare the older names and still work. - Write powers of ten as
\num{6.022e23}with siunitx, or ^{23} by hand. - Kelvin takes no degree sign: 300 K, not 300 °K.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
How do I write units in LaTeX?
Use siunitx, \qty{9.81}{\metre\per\second\squared}, or write them upright by hand: 9.81\,\mathrm{m\,s^{-2}}.
How do I write units in maths mode without a package?
Use \mathrm for the unit and a thin space before it, as in 5\,\mathrm{kg}.
How do I write a percentage with siunitx?
Write \qty{50}{\percent}.
What is the difference between \SI and \qty?
\qty is the current name in siunitx version 3; \SI is the older one and still works.