[Tex/LaTex] How to typeset units like MB, GB (megabytes, gigabytes)

units

Is there a simple way to typeset byte units like MB, GB, TB in latex in math mode? How do you typeset 1GB for example?

Best Answer

You can use siunitx, which supports both SI and binary prefixes (the latter, via the package option binary-units).

You can even define your own units via \DeclareSIUnit (though that is not necessary here since binary units are already defined in the library). Its main macro, \SI, works in math mode as well as in text:

\documentclass{article}
\usepackage[binary-units]{siunitx}

\begin{document}
    For example, $x = \SI{1}{\giga\byte}$ or \SI{1}{\gibi\byte}.
\end{document}

See page 38 of the siunitx manual for further information.