19

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}

enter image description here

The spacing around the \to seems off. Can you guys help me come up with a more robust solution?

6
  • I'm assuming you're referring to vertical space? Tried fiddling around with the vbox size?
    – 1010011010
    Aug 4, 2014 at 18:29
  • No i mean the space around the \to arrow looks off (i.e. horizontal spacing) also the font on the P is different.
    – bdeonovic
    Aug 4, 2014 at 18:32
  • You're looking for a solution that corrects the horizontal spacing of your symbol: I believe the command \DeclarePairedDelimiter comes very close to what you want.
    – 1010011010
    Aug 4, 2014 at 18:38
  • I don't understand, whats the pair?
    – bdeonovic
    Aug 4, 2014 at 18:48
  • Never mind. \mathrel is better suited. See @Mico's answer.
    – 1010011010
    Aug 4, 2014 at 18:49

2 Answers 2

17

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.

enter image description here

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{booktabs} % for '\midrule' macro
\usepackage{amsmath}  % for '\overset' macro
\usepackage{newpxmath,newpxtext}

% new \oset macro:
\makeatletter
\newcommand{\oset}[3][0ex]{%
  \mathrel{\mathop{#3}\limits^{
    \vbox to#1{\kern-2\ex@
    \hbox{$\scriptstyle#2$}\vss}}}}
\makeatother

\begin{document}
\[
\begin{array}[t]{@{}c@{}}
\text{with \texttt{\string\overset}}\\
\midrule
X_n\overset{P}{\to} X \\
X_n\overset{D}{\to} X \\
X_n\overset{j}{\to} X \\
X_n\overset{\text{rth}}{\to} X \\
X_n\overset{\text{i.i.d.}}{\sim} X
\end{array}
\qquad
\begin{array}[t]{@{}c@{}}
\text{with \texttt{\string\oset}}\\
\midrule
X_n\oset{P}{\to} X \\
X_n\oset{D}{\to} X \\
X_n\oset[.35ex]{j}{\to} X \\
X_n\oset[.45ex]{\text{rth}}{\to} X \\
X_n\oset[.6ex]{\text{i.i.d.}}{\sim} X
\end{array}
\]
\end{document}

Addendum, August 2022: I've received a request to explain how one would have to modify \oset to \uset, so as to place the supplemental material below rather than above the arrow. Here's how I think it should be done:

\makeatletter
\newcommand{\uset}[3][0ex]{%
  \mathrel{\mathop{#3}\limits_{
    \vbox to#1{\kern-7\ex@
    \hbox{$\scriptstyle#2$}\vss}}}}
\makeatother

The definition of \uset contains 2 changes relative to the definition of \oset:

  • ^ is replaced with _ ("underscore")

  • \kern-2\ex@ is replaced with \kern-7\ex@.


An additional remark: The material below the arrow is typeset in \scriptstyle math mode; that's fine for single letters or symbols. For longer expressions, such as i.i.d., you may want to reduce the font size a bit more. This may be done, say, by changing

X_n\uset{\textup{i.i.d.}}{\sim} X

to

X_n\uset{\textup{\tiny i.i.d.}}{\sim} X

I suppose this remark applies to both \uset and \oset. E.g., one may prefer the result of X_n\oset[.3ex]{\text{\tiny i.i.d.}}{\sim} X to that of X_n\oset[.6ex]{\text{i.i.d.}}{\sim} X.

5
  • Great answer, I have updated the question a bit, do you think you could come up with a good solution to handle those 4 cases I have listed? I tried tweaking the vbox argument but that didn't help much in the sim case.
    – bdeonovic
    Aug 4, 2014 at 19:16
  • @Benjamin - I've changed the definition of \oset so that an additional, optional parameter can be provided: the amount by which the superscript term should be raised (or lowered). The default value of the optional argument is 0ex.
    – Mico
    Aug 4, 2014 at 20:08
  • May I ask for the corresponding definition of \uset (for underset)? The naive idea of putting "_" in place of "^" is not working.
    – D.R
    Aug 24, 2022 at 2:05
  • 1
    @D.R - Please see the addendum I posted a few minutes ago.
    – Mico
    Aug 24, 2022 at 6:04
  • Thank you, this macro helped me a lot! But, I am still at pain to understand how to work in two places : what means the “vbox to#1”, and why is there a @ at the end of ex? I read @ is added in some local macros names, but I don't understand what it means with a unity.
    – mahaaaham
    Jan 15, 2023 at 18:36
9

I came around \lower and \raise TeX "primitives" here at https://www.tug.org/utilities/plain/cseq.html. And manually lower and raise a box in the \overset works fine for me.

\overset{\lower.5em\hbox{aaa}}{bbb}
1
  • 2
    I guess it's useful to know what "works fine for me" may mean in practice. I'd say the approach works sort of ok for minor vertical adjustments (of 0.4ex or less). Larger vertical adjustment values do not actually force the supplemental material closer to the arrow; instead, they just increase the line spacing between the line that precedes the \overset expression and the \overset expression itself.
    – Mico
    Aug 24, 2022 at 6:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .