[Tex/LaTex] How to adjust the fine positioning of stackrel

kerningstacking-symbols

I use stackrel to define a custom stacked relation symbol:

\def\qMapsfrom{\stackrel{?}{\Mapsfrom}}

However, the question mark is not centered properly and has too much distance from the \Mapsfrom. Is there a way to fine-adjust the vertical and horizontal spacing of \stackrel?

Best Answer

For the vertical spacing you can use \raisebox{<amount>}{<content>} to raise or lower (negative amount) the content. The horizontal centering was already shown for the similar question Overlay symbol with another, which might need a little adjustment here:

Here my suggestion. It works in the shown tests in all the different math modes.

\documentclass{article}

\usepackage{amsmath}
\usepackage{stmaryrd}

\newcommand\qMapsfrom{\mathrel{%
    \mathchoice{\qmf}{\qmf}{\scriptsize\qmf}{\tiny\qmf}%
}}
\newcommand\qmf{{%
    \setbox0\hbox{$\Mapsfrom$}%
    \rlap{\hbox to \wd0{\hss\hss\hss\raisebox{-.15\height}{?}\hss}}\box0
}}

\textwidth=2cm
\begin{document}

$ A \qMapsfrom B $

$ A \Mapsfrom B $

\[ A \qMapsfrom B \]
\[ A \Mapsfrom B \]

$ S_{ A \qMapsfrom B } $

$ S_{ A \Mapsfrom B } $

$ S_{S_{ A \qMapsfrom B }} $

$ S_{S_{ A \Mapsfrom B }} $

\end{document}

Update:

I just remembered that amsmaths \text can be used for math style depending scaling. It already uses similar code as the one above. This simplifies the macro to:

\newcommand\qMapsfrom{\mathrel{\text{%
    \setbox0\hbox{$\Mapsfrom$}%
    \rlap{\hbox to \wd0{\hss\hss\hss\raisebox{-.15\height}{?}\hss}}\box0
}}}

Result