# How to put symbols of equal size on top of each other?

I would like to put (any) two symbols on top of each other. With \overset the one on top is smaller. However, I want them to appear vertically centered and of equal size. How can this be done? Obviously, the following is quite a bad hack:

\documentclass{scrartcl}
\usepackage{amsmath}
\newcommand*{\ou}[2]{\overset{\text{\large ${#1}$}}{#2}}
\begin{document}
$a\ou{>}{<}0$ or $a\raisebox{-3pt}{\,$\ou{>}{<}$\,}0$ or $a\,{>\atop <}\,0$
\end{document}


\atop is not too bad, but a) how can I bring the symbols (vertically) closer to each other and b) how can this be defined as a command which takes care of the spacing around operators (\,)?

• For < and > is \gtrless, \lessgtr, \lesseqgtr, \gtreqless. Jun 22 '15 at 18:57

The symbol you want to build is already available, so this is just a hint for other similar situations. If you want to set symbols on top of one another, as opposed to superimpose symbols over each other, the tool to use is \ialign, not \ooalign that is handy for the latter case.

\documentclass{article}

\newcommand{\ou}{%
\mathrel{%
\vcenter{\offinterlineskip
\ialign{##\cr$<$\cr\noalign{\kern-1.5pt}$>$\cr}%
}%
}%
}

\begin{document}
$a \ou b$
\end{document}


I use \mathrel to declare the symbol type, \vcenter to make the whole construction centered with respect to the formula axis and \ialign with no baselineskip, so I can fine tune the spacing with \noalign{\kern...}.

Improvements with \mathpalette are possible for making the symbol available in all formula styles.

• Thanks egreg. I just realized: if one of the symbols is much wider than the other, they will not be vertically aligned anymore. Is there a way to get them automatically vertically aligned? Jun 23 '15 at 2:43
• @MariusHofert This much depends on the shapes of the symbols, so it's not possible to write code that does automatically what you want. Jun 23 '15 at 8:05

Let me start by saying that the amssymb package offers you out of the box the symbol you need as \lessgtr (there's also \grtless).

If you need, for some reason, to build the symbol by stacking < and >, one option is to use \ooalign with some \raiseboxes; the whole construct can then be passed as argument to \mathrel to get the proper spacing associated to a relational symbol.

The following code shows a comparisson between your original attempts (first line), the one using \ooalign (second line), and the symbol obtained using \lessgtr (third line):

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}

\newcommand*{\ou}[2]{\overset{\text{\large ${#1}$}}{#2}}

\newcommand\Ou{%
\mathrel{{\ooalign{\hss\raisebox{-0.5ex}{$>$}\hss\cr\raisebox{0.5ex}{$<$}}}}
}

\begin{document}

$a\ou{>}{<}0$ or $a\raisebox{-3pt}{\,$\ou{>}{<}$\,}0$ or $a\,{>\atop <}\,0$

$a\Ou 0$

$a\lessgtr 0$

\end{document}


• Hi Gonzalo, thanks for helping. Do you think this can be adapted to any symbols in math mode, not just > and <? Jun 22 '15 at 2:04
• @MariusHofert Sure. The approach with \ooalign is very versatile and can be used for other symbols too. See tex.stackexchange.com/a/22375/3954 to learn more about \ooalign. Jun 22 '15 at 2:10
• I tried to adapt it (with a 3rd argument for the space): \newcommand*{\ou}[3]{\mathrel{{\ooalign{\hss\raisebox{#3}{#1}\hss\cr\raisebox{-{#3}}{#2}}}}} and then called it with a\ou{>}{<}{0.5ex}0. Do you know how to get the 'negative sign' to work correctly? One could probably define a length and then set the corresponding negative length correctly, but that seems a bit tedious. Jun 22 '15 at 2:18
• @MariusHofert this should work: \newcommand\ou[3]{\mathrel{{\ooalign{\hss\raisebox{-#3}{$#1$}\hss\cr\raisebox{#3}{$#2$}}}}} and then in your document $a\Ou{>}{<}{0.5ex} 0$. Jun 22 '15 at 2:24
• @MariusHofert Of course, in my definition I assume that you want to stack math symbols (that's why I used $#1$ and $#2$). Jun 22 '15 at 2:26

The stackengine package provides ready made macros for such things, providing options for vertical placement and separation, as well as horizontal alignment.

\documentclass{article}
\usepackage{stackengine}
\stackMath
\begin{document}
CENTERED STACK:

Specify gap:\def\stacktype{S}
$x\mathbin{\stackanchor[0pt]{<}{>}}y\mathbin{\stackanchor[-1pt]{<}{>}}z$

Specify baselineskip:\def\stacktype{L}
$x\mathbin{\stackanchor[6pt]{<}{>}}y\mathbin{\stackanchor[5pt]{<}{>}}z$\medskip

OVER STACK:

Specify gap:\def\stacktype{S}
$x\mathbin{\stackon[0pt]{<}{>}}y\mathbin{\stackon[-1pt]{<}{>}}z$

Specify baselineskip:\def\stacktype{L}
$x\mathbin{\stackon[6pt]{<}{>}}y\mathbin{\stackon[5pt]{<}{>}}z$\medskip

UNDER STACK:

Specify gap:\def\stacktype{S}
$x\mathbin{\stackunder[0pt]{<}{>}}y\mathbin{\stackunder[-1pt]{<}{>}}z$

Specify baselineskip:\def\stacktype{L}
$x\mathbin{\stackunder[6pt]{<}{>}}y\mathbin{\stackunder[5pt]{<}{>}}z$
\end{document}