fontspec changes the size of the letter boxes

fontspec changes the size of the letter boxes. Compare

\documentclass{article}
%\usepackage{fontspec}

\begin{document}
\Huge\fbox{S}\fbox{F}
\end{document}


with the same code but \usepackage{fontspec} not commented out. In the figure, the left is without fontspec and the right is with it.

Is there a way to have them same size as without the fontspec package?

• Btw, this causes problems with chemfig package in alignment. In particular, when one wants to draw (tikz) nodes under atoms (letters) their vertical alignment goes wrong. – Mappi Aug 10 '14 at 17:52
• An additional observation: The behavior occurs under both LuaLaTeX and XeLaTeX. – Mico Aug 10 '14 at 17:55
• @Mico Yes, but XeLaTeX says both characters have the same height (with \fontcharht\font). – egreg Aug 10 '14 at 18:03
• The sizes of the capital letters take into account the overshoot, which is an error, in my opinion. – egreg Aug 10 '14 at 18:08
• Unlike TFM fonts, the height and depth of the glyphs in TTF/OTF fonts are taken from their bounding boxes and are not explicitly set by the font designer, so there is no way for the engine to identify overshots and the likes. – Khaled Hosny Aug 11 '14 at 0:29

This is due to bad font design, in my opinion. Instead of letting S overshoot its bounding box, the font developers decided to define a bounding box that vertically covers the whole inked area and has some sidebearings, as it becomes apparent when setting the parameter \fboxsep to zero:

\documentclass{article}
\usepackage{fontspec}
\begin{document}

\setlength{\fboxsep}{0pt}

\Huge
\fbox{S}\fbox{F}\fbox{f}\fbox{\itshape f}

\end{document}


Note that both sidebearings of the italic f are negative, whereas only the right sidebearing is negative for the upright f.

I don't know if this is an inherent limitation of OpenType fonts or just careless design: in a well crafted Roman font, all uppercase letters should have the same height and zero depth. Letters may overshoot the bounding box, but this overshoot should not be taken into account for determining the height and depth.

If you want a “capital letter box” macro, you can use an "I" as a model:

\documentclass{article}
\usepackage{fontspec}

\newcommand{\cfbox}{\fbox{\vphantom{I}\smash{#1}}}

\begin{document}

\Huge
\cfbox{S}\cfbox{F}

\end{document}


• Appreciate the information and the hack solution! Im still interested, why is this phenomenom observed only with fontspec ? – Mappi Aug 11 '14 at 18:45
• @Mappi If you don't load fontspec, the fonts selected are the same you load with pdflatex, that are properly designed. – egreg Aug 11 '14 at 19:20
• Just realized that the same thing happens with numbers in mathrm and mathsf environments. – Mappi Aug 12 '14 at 5:32
• Btw, doesn't this mean that with fontspec fonts are not really typeset on the same baseline? Isn't this super bad? – Mappi Aug 15 '14 at 13:50
• @Mappi Yes, they are. The first picture shows that the overshoot at the bottom is considered as depth. The bottom curve of the S should be below the baseline and it is. – egreg Aug 15 '14 at 13:57