4

I want to reduce the vertical space between a symbol and a letter that are above each other. I have the following code, using a new command $\oset$ that gives exactly the output I need. But unfortunately I get a compiling error, namely: missing $ inserted. When I use $\overset$ the output is wrong, but the compiler works..

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\oset}[2]{%
   {\mathop{#2}\limits^{\vbox to -.5\ex@{\kern-\tw@\ex@
    \hbox{\scriptsize #1}\vss}}}}
\makeatother

\begin{document}
$\oset{\sim}{t}$ gives a compiling error.
$\overset{\sim}{t}$ works, but the $\sim$ too high. 
\end{document}
Sven
  • 203
  • 2
    \hbox{$\scriptstyle #1$} – egreg Oct 29 '19 at 15:51
  • to establish link: https://tex.stackexchange.com/questions/194798/change-vertical-space-in-overset/194805?noredirect=1#comment1632361_194805 (I assume you got your code from @Mico's answer) – D.R Aug 24 '22 at 07:25

3 Answers3

4

It should be \hbox{$\scriptstyle#1$}. However, there's a better way:

\documentclass{article}
\usepackage{amsmath}

\makeatletter \newcommand{\oset}[2]{{\mathpalette\o@set{{#1}{#2}}}} \newcommand{\o@set}[2]{\o@@set{#1}#2} \newcommand{\o@@set}[3]{% \vbox{\offinterlineskip \ialign{\hfil##\hfil\cr $\m@th\o@set@demote{#1}#2$\cr \noalign{\vskip0.2pt} $\m@th#1#3$\cr }% }% } \newcommand{\o@set@demote}[1]{% \ifx#1\displaystyle\scriptstyle\else \ifx#1\textstyle\scriptstyle\else \scriptscriptstyle\fi\fi } \makeatother

\begin{document}

$\oset{\sim}{t}$ versus $\tilde{t}$

\end{document}

On the other hand, \tilde{t} seems much better.

enter image description here

For completeness here's how to define \uset and \ouset.

\documentclass{article}
\usepackage{amsmath}
\usepackage{accents} % for comparison

\makeatletter \newcommand{\oset}[2]{{\mathpalette\o@set{{#1}{#2}}}} \newcommand{\uset}[2]{{\mathpalette\u@set{{#1}{#2}}}} \newcommand{\ouset}[3]{\oset{#1}{\uset{#2}{#3}}}

\newcommand{\o@set}[2]{\o@@set{#1}#2} \newcommand{\o@@set}[3]{% \vbox{\offinterlineskip \ialign{\hfil##\hfil\cr $\m@th\ou@set@demote{#1}#2$\cr \noalign{\vskip0.2pt} $\m@th#1#3$\cr }% }% } \newcommand{\u@set}[2]{\u@@set{#1}#2} \newcommand{\u@@set}[3]{% \vtop{\offinterlineskip \ialign{\hfil##\hfil\cr $\m@th#1#3$\cr \noalign{\vskip0.6pt} $\m@th\ou@set@demote{#1}#2$\cr }% }% } \newcommand{\ou@set@demote}[1]{% \ifx#1\displaystyle\scriptstyle\else \ifx#1\textstyle\scriptstyle\else \scriptscriptstyle\fi\fi } \makeatother

\begin{document}

$\oset{\sim}{t}$ versus $\tilde{t}$

$\uset{x}{t}$ versus $\underaccent{x}{t}$

$\ouset{\sim}{x}{t}$ versus $\underaccent{x}{\tilde{t}}$

\end{document}

enter image description here

egreg
  • 1,121,712
  • I was trying to generalize your \oset into \uset (underset) and \ouset (overunderset), but couldn't quite figure it out. Do you mind also writing these commands? – D.R Aug 24 '22 at 07:41
  • 1
    @D.R I added it – egreg Aug 24 '22 at 14:08
  • thank you. I was playing around, and \ouset{}{}{} works great with letters, and the plus and minus signs, but there is some asymmetry when I use it on \to or the equal sign. This is not so important for my use cases, but it'd be nice to know why. – D.R Aug 24 '22 at 17:05
  • @D.R The bounding box of \to is “peculiar”. – egreg Aug 24 '22 at 17:54
2

Remember: it is possible to use also mtpro2 (I like very much this package), lite version. Here there are several examples in relation to your tastes for the lenghts of the tilde symbol. The vertical spacing is automatic.

enter image description here

\documentclass{article}
\usepackage[lite]{mtpro2}
\begin{document}
\[
\tilde t+\wtilde t +\wwtilde t+\widetilde t
\]
\end{document}
Sebastiano
  • 54,118
1

Why not use the \accentset command?

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{accents}

\begin{document}

$\accentset{\sim}{t}$ compared to $ \tilde{t} $ and to $\widetilde{t}$

\end{document} 

enter image description here

Bernard
  • 271,350