# Height of box with arrow

Consider the following example:

\documentclass{article}

\begin{document}

\fbox{$\longrightarrow$}

\end{document}


As can be seen, the height of the box is too small.

How do I correct this?

In 1992, the Computer Modern arrows were changed to make for a larger head; already in the old version the bounding box didn't cover the whole tip and it was not changed after the modification to the tips, for backwards metric compatibility.

With the old-arrow package one can see the difference:

\documentclass{article}
\usepackage[old]{old-arrows}

\begin{document}

\setlength{\fboxrule}{0.1pt}
\setlength{\fboxsep}{0pt}

x \fbox{$\varrightarrow$} (old style)

x \fbox{$\rightarrow$} (new style)

\end{document}


You can fix the bounding box using the fact that the stem is at the math axis and the lower part of the tip sits on the baseline.

\documentclass{article}

\newcommand{\srightarrow}{%
\mathrel{\mathpalette\strutarrow\rightarrow}%
}
% define similarly the other arrows you need

% the generic macro
\newcommand{\strutarrow}[2]{%
\vrule width 0pt height 2\fontdimen22
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi 2
{#2}%
}

\begin{document}

\fbox{$\rightarrow$} \fbox{$\srightarrow$}

\setlength{\fboxrule}{0.1pt}
\setlength{\fboxsep}{0pt}

x \fbox{$\rightarrow$} (normal)

x \fbox{$\srightarrow$} (with strut)

\end{document}


• Thank you, Enrico! (Btw. when I zoom in it is easy to see that the long arrow (when I switch to \longrightarrow) is composed of a short arrow and a line segment. Can this be "smoothed" out?) – Svend Tveskæg Jan 17 '18 at 0:57
• @SvendTveskæg That’s how long arrows are made, some viewers may have issues at certain resolutions. It has nothing to do with the bounding box. – egreg Jan 17 '18 at 6:59

You can add a strut or perhaps better add a zero width rule similarly centred on the math axis, of whatever size you wish.

\documentclass{article}

\begin{document}

\fbox{.} \fbox{$a$} \fbox{$\longrightarrow$} \fbox{\strut$\longrightarrow$}

\fbox{$\vcenter{\hrule height 15pt width 0pt}{\longrightarrow}$}

\end{document}

• Hmmm! When I zoom in it is easy to see that the long arrow is composed of a short arrow and a line segment. Can this be "smoothed" out? – Svend Tveskæg Jan 17 '18 at 0:27
• @SvendTveskæg one way would be to use a font that has long arrows eg stix, or you could tweak the definition of \joinrel  to have more overlap – David Carlisle Jan 17 '18 at 1:05
• @SvendTveskæg much as it pains me to say so, I suspect you should move the tick in the general direction of egreg – David Carlisle Jan 17 '18 at 9:13
• Okay; I will. :-) – Svend Tveskæg Jan 17 '18 at 17:57

Here is a solution:

\documentclass[12pt]{article}

\begin{document}

hkl \raisebox{2\fontdimen22\textfont2}{ \fbox{\raisebox{-2\fontdimen22\textfont2}{$\longrightarrow$}}} amn

\end{document}


• Thanks! Hmmm! When I zoom in it is easy to see that the long arrow is composed of a short arrow and a line segment. Can this be "smoothed" out? – Svend Tveskæg Jan 17 '18 at 0:29
• I didn't notice that – thought it was a glyph on its own. You can use this: \newcommand\mylongrightarrow{\mathrel{\relbar\mkern-4mu\rightarrow}}. The difference in length is very small: about 0.7pt. – Bernard Jan 17 '18 at 0:42
• @SvendTveskæg: Strange… I've just tested your code and I have no problem. Could you post a complete example reproducing your problem? – Bernard Jan 17 '18 at 0:56
• I'm very tired ... going to bed now. I'll post tomorrow. Thank you for your help so far. – Svend Tveskæg Jan 17 '18 at 0:59