170

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?

3 Answers 3

168

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.
    
19
  • 9
    @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". Commented Oct 18, 2010 at 8:29
  • 1
    Is there a difference between \linewidth and \textwidth? Commented Oct 18, 2010 at 9:28
  • 12
    @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/… Commented Oct 18, 2010 at 10:30
  • 2
    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. Commented Jun 22, 2011 at 10:29
  • 1
    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
    Commented Jun 28, 2011 at 10:14
71

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:

1em and 1ex in Computer Modern fonts

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.

1em and 1ex for Latin Modern in pdfLaTeX

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.

1em and 1ex for Latin Modern fonts in XeLaTeX

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.

1em and 1ex for some other 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.

6
  • 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
    Commented Feb 13, 2013 at 4:24
  • Just out of curiosity, what are the results for Latin Modern with pdflatex?
    – Xavier
    Commented Feb 13, 2013 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
    Commented Feb 13, 2013 at 6:33
  • 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'
    Commented Feb 13, 2013 at 7:41
  • @Johan_E It would be great if you put the code in there that generated the tables. Commented Nov 14, 2016 at 11:25
22

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .