Skip to main content
The 2024 Developer Survey results are live! See the results
Final comment
Source Link
egreg
  • 1.1m
  • 139
  • 2.7k
  • 4.3k

The value of 1em is not necessarily the width of any capital letter (its name refers to the width of a capital M, but it's not necessarily so and the value is basically the font designer's decision).

Similarly, 1ex traditionally refers to the height of a lowercase x, but it may not be if the font designer decided otherwise.

LaTeX provides a standard way to get the width and height of a character (or of a bunch of characters):

\settoheight{\mylen}{A}
\settowidth{\mylen}{A}
\settodepth{\mylen}{g}

will assign \mylen (which should have been declared with \newlength{\mylen}) the corresponding dimensions at point of call.

If you want to record the height of a typical capital letter at the default font size for later usage, do

\newlength{\ucht}
\AtBeginDocument{\settoheight{\ucht}{A}}

because some font packages do their set up at begin document and doing \settoheight in the preamble may not reflect the main document font.

If you want to use the height of a capital letter depending on the current font, the construction \fontcharht\font`A can be used wherever a length is needed.

An esteemed community member objects in comments that using A or X could lead to different results. Indeed this can be true for some fonts. In Computer Modern all capital letters are assigned the same height, even if some of them “overshoot” it: typically A, C, G, O, Q. Other fonts may be subject to different decisions by the designer, so a bit of experimentation is needed with the actual document font.

The value of 1em is not necessarily the width of any capital letter (its name refers to the width of a capital M, but it's not necessarily so and the value is basically the font designer's decision).

Similarly, 1ex traditionally refers to the height of a lowercase x, but it may not be if the font designer decided otherwise.

LaTeX provides a standard way to get the width and height of a character (or of a bunch of characters):

\settoheight{\mylen}{A}
\settowidth{\mylen}{A}
\settodepth{\mylen}{g}

will assign \mylen (which should have been declared with \newlength{\mylen}) the corresponding dimensions at point of call.

If you want to record the height of a typical capital letter at the default font size for later usage, do

\newlength{\ucht}
\AtBeginDocument{\settoheight{\ucht}{A}}

because some font packages do their set up at begin document and doing \settoheight in the preamble may not reflect the main document font.

If you want to use the height of a capital letter depending on the current font, the construction \fontcharht\font`A can be used wherever a length is needed.

The value of 1em is not necessarily the width of any capital letter (its name refers to the width of a capital M, but it's not necessarily so and the value is basically the font designer's decision).

Similarly, 1ex traditionally refers to the height of a lowercase x, but it may not be if the font designer decided otherwise.

LaTeX provides a standard way to get the width and height of a character (or of a bunch of characters):

\settoheight{\mylen}{A}
\settowidth{\mylen}{A}
\settodepth{\mylen}{g}

will assign \mylen (which should have been declared with \newlength{\mylen}) the corresponding dimensions at point of call.

If you want to record the height of a typical capital letter at the default font size for later usage, do

\newlength{\ucht}
\AtBeginDocument{\settoheight{\ucht}{A}}

because some font packages do their set up at begin document and doing \settoheight in the preamble may not reflect the main document font.

If you want to use the height of a capital letter depending on the current font, the construction \fontcharht\font`A can be used wherever a length is needed.

An esteemed community member objects in comments that using A or X could lead to different results. Indeed this can be true for some fonts. In Computer Modern all capital letters are assigned the same height, even if some of them “overshoot” it: typically A, C, G, O, Q. Other fonts may be subject to different decisions by the designer, so a bit of experimentation is needed with the actual document font.

Source Link
egreg
  • 1.1m
  • 139
  • 2.7k
  • 4.3k

The value of 1em is not necessarily the width of any capital letter (its name refers to the width of a capital M, but it's not necessarily so and the value is basically the font designer's decision).

Similarly, 1ex traditionally refers to the height of a lowercase x, but it may not be if the font designer decided otherwise.

LaTeX provides a standard way to get the width and height of a character (or of a bunch of characters):

\settoheight{\mylen}{A}
\settowidth{\mylen}{A}
\settodepth{\mylen}{g}

will assign \mylen (which should have been declared with \newlength{\mylen}) the corresponding dimensions at point of call.

If you want to record the height of a typical capital letter at the default font size for later usage, do

\newlength{\ucht}
\AtBeginDocument{\settoheight{\ucht}{A}}

because some font packages do their set up at begin document and doing \settoheight in the preamble may not reflect the main document font.

If you want to use the height of a capital letter depending on the current font, the construction \fontcharht\font`A can be used wherever a length is needed.