# [Tex/LaTex] Which measurement units should one use in LaTeX

best practicesunit-of-measure

There are various measurement units that one can use (such as pt, mm, in, em, ex etc.) for specifying lengths and heights. For font-based units (em and ex) the actual spacing will vary slightly depending on the font. For the other types of units the spacing is fixed at the given measurement.

Is it better to prefer some of these units over others in certain situations? For example, is the "em" unit better than a fixed measurement when specifying lengths for indenting text eg. when setting xleftmargin, and xrightmargin in the listings package. When would you use the "ex" unit for specifying heights? I imagine fixed units should always be used when setting page margins.

So, I guess what I am asking is, what are the guidelines for deciding which measurement units to use?

There are no hard-and-fast rules, but here's a short list of guidelines:

• "1em" can be considered a horizontal length and "1ex" a vertical one, so use them accordingly but mix and match as you need (they are horizontal and vertical arbitrarily, but usually you hear people talk about "1em" is the width of an "m" — usually false — and "1ex" is the height of an "x" — usually true). I usually consider 1em to be about the same size as the font size in points.

• em and ex are relative lengths, so they're better for designing around text; like you say, an indent of 2em will work whether the fontsize is 9pt or 12pt.

• Things that are of fixed size (such as the page size) should be defined with fixed units, of course.

• When things should be relative, it will often make more sense to define them in terms of the page design. For example, width=0.5\linewidth might make more sense than width=5cm for a figure.

• Watch out for the pt unit! In TeX, 1pt is 1/72.27in, whereas the more common "PostScript point" used by most other software is 1/72in which in TeX is 1bp. If you're dealing with other programs and need your lengths exact, use bp or use standard cm or in measurements.

• Remember that TeX uses fixed point arithmetic, so there are precision problems when you hit around five significant figures. E.g.,

  \newlength\x
\x=1in
\showthe\x


gives

  > 72.26999pt.