40

Is it possible to overlay a symbol with another?

I want to write an equal sign with a question mark overlayed (or the other way around).

Note I don't want

\stackrel{?}{=}

I want the question mark to be right on top, to cross over the equal sign (which creates kind of a new sign).

Is this possible? How? Or is there a one character sign for this?

3
  • Can you try this? \DeclareMathOperator{\maybe}{\stackrel{?}{=}}
    – Chuang
    Commented Mar 7, 2011 at 20:17
  • There must be a better way, but \DeclareMathOperator{\overlay}{?\hspace{-9pt}=} seems to work. With this version you'll have to adjust the spacing depending on the size of the font and the characters being overlaid. Commented Mar 7, 2011 at 20:39
  • @masterxilo: Thanks for accepting my answer. However in the meantime better answers appeared and one of it should be accepted to indicate the preferred solution to other users with the same issue. Commented Jul 19, 2011 at 10:25

3 Answers 3

39

You can overlay the symbols the following way: Box the wider one and let the other one lap over it (using \rlap or \llap). The correct centering is achieved by placing the second character into a box with the equal width but using \hss to center it. The correct size for the different math modes can be adjusted using \mathchoice.

\documentclass{article}
\def\qeq{\mathrel{%
    \mathchoice{\QEQ}{\QEQ}{\scriptsize\QEQ}{\tiny\QEQ}%
}}
\def\QEQ{{%
    \setbox0\hbox{=}%
    \rlap{\hbox to \wd0{\hss?\hss}}\box0
}}

\textwidth=2cm
\begin{document}

$ A \qeq B $

$ A = B $

\[ A \qeq B \]
\[ A = B \]

$ S_{ A \qeq B } $

$ S_{ A = B } $

$ S_{S_{ A \qeq B }} $

$ S_{S_{ A = B }} $

\end{document}

Result

Result

5
  • 4
    For centering there's \mathclap if you're willing to load mathtools. Commented Mar 7, 2011 at 21:10
  • Thanks @Hendrik, mathtools seems to be the way to go. I didn't know it before. As an engineer I'm not doing this much math with LaTeX... Commented Mar 7, 2011 at 21:12
  • Thanks a lot for this, exactly what I was looking for! However, this seems pretty complex for something I'd expect LaTeX to have built-in support for. Doesn't anyone ever use this sign? I use it all the time to start proofs...
    – masterxilo
    Commented Mar 7, 2011 at 22:28
  • @masterxilo: I've never seen it before. I don't believe it's a common symbol in math or computer science. Maybe it is unique to your field.
    – TH.
    Commented Mar 10, 2011 at 9:04
  • It didn't work for math mode symbols: tried with \cdot and \Diamond and got a missing $ error. Commented Jul 1, 2018 at 6:30
32

You could also use the Plain macro \ooalign:

$\mathrel{\ooalign{\hss?\hss\cr=}}$\bye
3
  • (Plain) TeX never ceases to amaze me. Commented Mar 8, 2011 at 8:02
  • 2
    And while morbusg gave a plain TeX MWE, the code between the $ works perfectly in LaTeX. Commented Mar 8, 2011 at 8:07
  • 2
    See the answer by egreg to similar question why you'd want to use '\hidewidth' instead of '\hss': tex.stackexchange.com/questions/22371/…
    – morbusg
    Commented Jul 19, 2011 at 13:42
11

The just submitted stackengine package is tailor made for combining glyphs. Since it was just submitted to CTAN, it will hopefully propagate this weekend.

\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx}
\parskip 1ex\parindent 0in
\begin{document}
%Arguments to inset commands{overlay image}{base image}{V-offset}{H-offset}
Relative to bottom vs. top:\\
\bottominset{*}{O}{}{}%
\topinset{*}{O}{}{}%

With V and H shifting:\\
\topinset{*}{O}{}{}%
\topinset{*}{O}{1pt}{}%
\def\stackalignment{r}%
\topinset{*}{O}{2pt}{-1pt}%

Glyphs of different scales:\\
\def\stackalignment{c}%
\def\newi{\stackon[-.4ex]{i}{\scalebox{3}{.}}}
\def\useanchorwidth{T}
Th\newi s uses width of anchor alone

\def\useanchorwidth{F}
Th\newi s uses width of complete stack
\end{document}

enter image description here

1
  • 1
    Later revisions of stackengine deprecate \topinset and \bottominset, and replace them both with \stackinset. It gives more alignment options and has a syntax more suited for nesting. Commented Feb 4, 2014 at 22:45

You must log in to answer this question.

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