# Where should 1em be defined - when to use lengths in “em”

The table in the document below looks as expected when using the article document class. With other document classes, the rules dissapear.

The reason seems to be that booktabs defines the with of the rules in units of em which is apparently not set in some documentclasses, e.g. revtex4-1 (which I was using).

\documentclass{article}
%\documentclass{revtex4-1} % 1em=0pt
%\documentclass{minimal}   % 1em=0pt
\usepackage{booktabs}
\newlength\mylength
\setlength\mylength{1em}%

\begin{document}

\begin{tabular}{ll}
\toprule
Light rule width:&\the\lightrulewidth\\
\midrule
Heavy rule width:&\the\heavyrulewidth\\
\midrule
Width of 1em:&\the\mylength \\
\bottomrule
\end{tabular}

\end{document}


Where should the em unit be defined? Is it the job of the class, font package or the document author? When should I avoid using lengths in units of em?

-
The em is a parameter from the font. It is not defined in a class. –  jfbu Jan 23 '13 at 18:26
And this actually a problem when for example the standard LaTeX2e kernel uses the em in its typesetting of the table of contents: for some font where this em is too small, subsections and even worse subsubsection entries show an overlap between the entry number and the entry name. –  jfbu Jan 23 '13 at 18:29
@jfbu: the "standard classes" were designed with the cm fonts in mind. they happen to work with many other fonts, but one should in principal design layouts with a font in mind. if some particular font's design doesn't work with the standard classes, it's the class that should change, not the font. (and of course, you change a standard class by creating a new one that goes \LoadClass{article} (or whatever) and then patching the parameters as needed.) –  wasteofspace Jan 23 '13 at 19:00

When you say \setlength{\mylength}{1em}, the real length stored in \mylength will depend on the font that is current at the time of the assignment.

Each font defines its own em unit; for instance it is 10pt for the usual Computer Modern Roman at 10pt; it is 19pt for \huge (which is Computer Modern Roman at 20.7pt).

If you say \hspace{1em}, the current size of the em is used. For some reasons (that I don't understand), the revtex4-1 class doesn't issue the \normalsize and \normalfont commands, so in the preamble the current font is still the "null" one, which has all font parameters zero. Only at begin document the main document font is established.

Conversely the standard classes (not minimal) issue the command \normalsize after having defined it, so the em unit will have a value. Possibly not the one for the main document font, however: some font packages delay selecting the main font at begin document.

When to choose the em unit for setting a length? I recommend only some specific cases, that is, the lengths that should depend on the main font size. An important case is \parindent. Great typographers recommend that the normal paragraph indent should be 1em; if you want to ensure this and not rely on the LaTeX default (for the standard classes) of 15pt, then

\AtBeginDocument{\setlength{\parindent}{1em}}


will do the right thing, provided this is issued after having loaded the font packages. Also other lengths could be set in terms of the main font's em: all those regarding list indentations, for instance, which shouldn't depend on the relative font size.

For "explicit" horizontal lengths, using em is recommendable, but one can also choose fractions of the column width: it mostly depends on the specific application.

NOTE. The behavior of revtex4-1 is nonstandard and should be corrected, in my opinion. Some packages rely on a default em for setting their own defaults (which is a good guess in many cases). If you issue \normalsize before doing settings that involve the em, you'll get it. Having to issue \normalsize before loading booktabs is to be considered a bug.

-
Thanks, I have notified the REVTeX maintainers about the missing \normalsize. While this is nonstandard for a document class, do you consider not issuing \normalsize in the booktabs package prior to setting up rules in units of em to be a booktabs-bug? –  Martin Heller Jan 24 '13 at 9:50
@MartinHeller No; packages expect that the class issues \normalsize. –  egreg Jan 24 '13 at 11:30

The other documentclasses fail to select fonts on loading. As the em unit is defined in terms of the current font this can be fixed by adding the command \normalfont before loading booktabs (and after any font packages that might be relevant), which expects em to be defined:

\documentclass{revtex4-1}
\normalfont
\usepackage{booktabs}
\newlength\mylength
\setlength\mylength{1em}%

\begin{document}

\begin{tabular}{ll}
\toprule
Light rule width:&\the\lightrulewidth\\
\midrule
Heavy rule width:&\the\heavyrulewidth\\
\midrule
Width of 1em:&\the\mylength \\
\bottomrule
\end{tabular}

\end{document}


When using the article documentclass, you load article.cls which in turn loads size10.clo (for 10pt). This .clo file includes the call \normalsize which in turn includes a \selectfont command, bringing the current font in to action.

-