# Which measurement units should one use in LaTeX?

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" is a horizontal length and "1ex" a vertical one, so use them accordingly (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.

-
@Will: Bringhurst says: (2.1.1) "1 em is a distance equal to the type size", so you can be more certain than "usually consider". BTW, I'm thinking of changing my id to "BringhurstSycophant". –  Brent.Longborough Oct 18 '10 at 8:29
@maxschlepzig: Yes. \textwidth is the width of the whole text area on the page. \linewidth is the width of the current line, so in a column it is equal to \columnwidth. See this answer: tex.stackexchange.com/questions/275/… –  Brent.Longborough Oct 18 '10 at 10:30
About the scale. Engineering drafts and geographic maps have mandatory integer scale. And these draftsmen were the people that did all the graphics in the books of the past (which in most cases are incomparably more simple and beautiful than what PSTricks or PGF/TikZ can do). Many people wonder how beautiful these books are. But now days, having computers, instead of making things more precise, they are made very arbitrary. And here comes another thing for the page layout - doing arbitrary margins and arbitrary figure sizes isn't beautiful too. –  Karl Karlsson Jun 22 '11 at 10:29
A small remark. When the class or the document states that \parindent is 2em, that dimension is relative to the font (and size) which is current at that time; if one doesn't pay attention it may be Computer Modern (not that it makes a big difference, in general). Anyway, it won't change size in, say, a \small context. Tschichold argues that one should always have \parindent= font size, but it's another matter. –  egreg Jun 28 '11 at 10:14
@StrawberryFieldsForever — I mean that as a rule of thumb, if you load a 12pt font then 1em ≈ 12pt. –  Will Robertson Jun 15 '12 at 5:46

Reading these answers, and comments to them, piqued my curiosity… Especially this sentence that Will Robertson wrote in his answer:

[...] I usually consider 1em to be about the same size as the font size in points.

It inspired me to investigate the actual behavior of TeX (or rather LaTeX). Since my findings could be of interest to those finding this question, I post them here.

# Computer Modern

I started of by checking what length 1em and 1ex are for different selection of Roman/Serif/Typewriter, Medium/Bold, and Upright/Italic/Slanted/SmallCaps. Here are the results:

As we can see, 1em varies quiet a lot; from 10.00 pt to 11.82 pt. The length of 1ex is more consistent, with only three different values for all the different styles.

In the table some actual measurements of the font is included. These are the width of an “M” (measured as \wd of an \hbox{M} created when the font is active) and the height and depth of an “x” (measured similarly as \ht and \dp of an \hbox{x}).

An interesting point of this table is that 1em is neither 10 pt (the selected font size) or the M-width. On the other hand, 1ex corresponds exactly to the height of an “x”, except for typewriter small caps.

# Latin Modern

[Xavier asked about the results for Latin Modern using pdfLaTeX, so I added this section.]

To check the values for Latin Modern using pdfLaTeX I added this to the preamble:

\usepackage{lmodern}
\usepackage[T1]{fontenc}


Some more styles are available, compared to Computer Modern, so I added them to the list. Also, the bold italic typewriter style was not available for Latin Modern, so I removed it.

The values of this table corresponds to the values for Computer Modern to within a hundredth of a point for the columns 1em, M-height, 1ex and x-depth (all zero again).

This time it’s a bit different for the x-height values. For the most part they correspond to the value of 1ex. However they do not correspond for these styles: medium small caps roman, all medium sans, and all typewriter styles apart from medium italic.

# XeLaTeX and Latin Modern

Generating the above tables with XeLaTeX instead of pdfLaTeX, without changing the code, results in exactly the same values.

I continued the investigation with XeLaTeX and the Latin Modern fonts. I used fontspec to load the fonts “manually” with \fontspec{fontname} where fontname is given in the first column of the table. [See note in Conclusions regarding fontspec.] This uses the system wide (non TeX specific) catalogue, via the fontconfig library, to locate and load the fonts. In this particular case it loads Type1 fonts (.pfb-files) that just happen to live in my main texmf tree.

Once again, the values for 1ex matches the measured x-height exactly (even when x-depth is non-zero). This time, however, 1em is exactly the specified font size (10 pt). One more thing to note is that the measured values correspond to the values for Computer Modern (rounded to hundredths of points) except for when the x-depth is non-zero.

# More fonts

For good measures, I also compiled a table for some other fonts. These are all TrueType and OpenType fonts.

# Conclusions

[Edit: after adding the section on Latin Modern in pdfLaTeX, I have reconsidered some of the conclusions.]

The font metric mechanism seems to differ between using TFM fonts and Xe(La)TeX’s new font support.

## (non-Xe)LaTeX

(this also applies to XeLaTeX using TFM fonts.)

• The value of 1em is not equal to the seleted size of the font, nor is it the width of an actual “M”.
• The value of 1ex is not tied to the size of an actual “x”.

However, from the presented data I can conclude that 1ex is most often the height of an actual “x” (\ht of \hbox{x}); while the value of 1em is (almost?) never the width of an “M” (\wd of \hbox{M}).

## XeLaTeX/fontspec

Note: I realize that this probably has nothing to do with fontspec, per se. It is more the question of “old” vs. “new” font handling mechanisms in the engine. However I use the phrase XeLaTeX/fontspec to differentiate the new font handling from the TFM font handling still present in the XeTeX engine.

From the collected data I conclude that, for non-TFM fonts:

• The value of 1em is exactly the selected font size.
• The value of 1ex is exactly the height of an “x”. (\ht of \hbox{x})

## Different Sizes

Regarding different font sizes, I have done some runs for 12 pt text, and found nothing surprising. Just remembering that the Computer Modern fonts have optical sizes so 1em and 1ex will (probably) depend on the font size in a non-simple way.

-
Very interesting for Computer Modern. I would love to know how LaTeX defines 1em; typographically, it is (nowadays) defined as equal to the font size, so clearly there is something weird happening with Computer Modern (or with your calculations). Maybe you just discovered a last TeX bug :) –  Xavier Feb 13 '13 at 4:24
Just out of curiosity, what are the results for Latin Modern with pdflatex? –  Xavier Feb 13 '13 at 4:25
@Xavier: The Latin Modern fonts (with pdfLaTeX) showed some surprising results... 1ex not equal to \ht of \hbox{x}! Check the updated answer. –  Johan_E Feb 13 '13 at 6:33
Thanks! Really weird results... –  Xavier Feb 13 '13 at 7:11
Remark: in typewriter fonts, it makes sense that all values of (1em, 1ex) are equal, no matter which series or style you use. In other fonts, similar approach makes sense, too. That's why they do not correspond. –  yo' Feb 13 '13 at 7:41

To fill in a couple of gaps that Will didn't address: English-speaking typographers will specify the measure (\textwidth) in pc and the leading (\baselineskip) in pt; continental European typographers will use cc and dd for the same purposes (not that you'll see much difference).

There's no particular reason for preferring these units other than tradition.

-
Now you're giving me TeXBook flashbacks. –  Matthew Leingang Oct 18 '10 at 4:17
Interesting, I didn't know about cc (cicero) and dd (didôt point) units. –  Steve Oct 19 '10 at 12:13
@Lev: What if you are an English-speaking European (a Briton)? :) –  StrawberryFieldsForever Jun 12 '12 at 12:20