How can I decrease the space in overset? I found this solution online, but it doesn't look quite like the original overset (note I know it is difficult to come up with a solution to handle all cases elegantly, but I have listed 4 common use cases that would like to look good)
\documentclass[11pt]{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
%overset spacing
\makeatletter
\newcommand{\oset}[2]{%
{\mathop{#2}\limits^{\vbox to -.5\ex@{\kern-\tw@\ex@
\hbox{\scriptsize #1}\vss}}}}
\makeatother
\usepackage{newpxmath}
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[utf8]{inputenc} % Required for including letters with accents
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\begin{document}
I would like it to work for the following examples:
Original 1: $X_n\overset{P}{\to} X$
Original 2: $X_n\overset{D}{\to} X$
Original 3: $X_n\overset{\text{$r$th}}{\to} X$
Original 4: $X_n\overset{\text{i.i.d.}}{\sim} X$
Testing 1: $X_n\oset{P}{\to} X$
Testing 2: $X_n\oset{D}{\to} X$
Testing 3: $X_n\oset{\text{$r$th}{\to} X$
Testing 4: $X_n\oset{\text{i.i.d.}{\sim} X$
\end{document}
The spacing around the \to
seems off. Can you guys help me come up with a more robust solution?
Best Answer
To get better horizontal spacing of the
\oset
macro -- specifically, to make its spacing the same as that of a "relational operator" (which is the case for\to
) -- you could encase the macro's definition in a\mathrel
wrapper.To make the
\oset
macro usable for different symbols/letters in the base and superscript positions, it's necessary to introduce a third, optional, argument: the argument of\vbox
. Its default value,0pt
is suitable for single uppercase letters in the superscript position and arrows in the base position. For other combinations, you'll need to experiment a bit to find the suitable distance by which the superscript term should be raised; the values given in the example below may be OK for the selected math font (newpxmath
). Different values will probably need to be chosen if you use a different math font.