2

I am trying to set a length to the height of a heading. I have the following snippet.

% heading height
\settoheight{\headingh}{\Huge{\textbf{\heading}}}

\centering\Huge\textbf{\heading}\rule{0.1mm}{\headingh}

The result of which is the following.

Heading Height

As you can see, the letter is slightly taller than the rule. If I run \settoheight on the rule, the resulting length is the same as the \headingh length.

Here is a minimum reproducible example.

\documentclass[11pt]{article}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}

\newlength{\headingh}

\begin{document}
\settoheight{\headingh}{\Huge\textbf{A}}
\Huge\textbf{A}\rule{0.1mm}{\headingh}
\end{document}

I have used the same font as in the original, but the same effect is present even when the default font is used, i.e. with lines 2-4 commented out.

Bernard
  • 271,350
  • 1
    This is why: https://tex.stackexchange.com/questions/275374/what-is-the-local-height-of-a-capital-letter/275381#275381 See "overshoot" https://ilovetypography.com/2009/01/14/inconspicuous-vertical-metrics/ – Steven B. Segletes May 14 '20 at 18:23
  • You might want to use \ht\strutbox instead. It is faster and at least should be big enough. – John Kormylo May 14 '20 at 18:27
  • @StevenB.Segletes That begs the question, is there a way to measure the actual height automatically with a latex script? – user110971 May 14 '20 at 18:40
  • Apparently, not directly in LaTeX. See https://tex.stackexchange.com/questions/165961/how-to-crop-background-from-image-automatically – Steven B. Segletes May 14 '20 at 18:59

1 Answers1

5

It is the choice of the font designer, the height depth and width of each character is specified in the font metrics, they are not measured from the visible shape of the character. pdftex has no information about which pixels are black and which white, each character is just a rectangle.

David Carlisle
  • 757,742