Put a symbol above another

math-modesubscriptssuperscriptssymbols

Following this question, I'm having problems when using the accepted answer on subscripts.

\[ 
A_  {z {_{y}^{x}} {_{x}^{y}} } \qquad
    {z {_{y}^{x}} {_{x}^{y}} }
\]

I don't know why, when in a subscript, the alignement/centering messes up.

I've also tried other options. I'll comment them a bit.

  • \atop , \genfrac and \above
\[
A_  {z {x \atop y} {y \atop x} } \qquad
    {z {x \atop y} {y \atop x} }
\]
\[ 
A_  {z {\genfrac{}{}{0pt}{2}{x}{y}} {\genfrac{}{}{0pt}{2}{y}{x}} } \qquad
    {z {\genfrac{}{}{0pt}{2}{x}{y}} {\genfrac{}{}{0pt}{2}{y}{x}} }
\]
\[
A_  {z {x \above 0pt y} {y \above 0pt x} } \qquad
    {z {x \above 0pt y} {y \above 0pt x} }
\]

They seem to render exactly the same. They have too much blank space.

  • \stackanchor from "stackengine" package
\stackMath
\[
A_  {z {\stackanchor{x}{y}} {\stackanchor{y}{x}} } \qquad
    {z {\stackanchor{x}{y}} {\stackanchor{y}{x}} }
\]

In both cases, it's misaligned. In the subscript, it's not the right size,

  • \overset from "mathtools" package and \stackrel
\[
A_  {z {\overset{x}{y}} {\overset{y}{x}} } \qquad
    {z {\overset{x}{y}} {\overset{y}{x}} }
\]
\[
A_  {z {\stackrel{x}{y}} {\stackrel{y}{x}} } \qquad
    {z {\stackrel{x}{y}} {\stackrel{y}{x}} }
\]

They seem to render exactly the same. In both cases, not centered, neither the correct size.

By "aligned" I mean "$xy$ alignment", so "misaligned" refers to anything else.
There's no need that it renders strictly perfect aligned, centered or sized: something close will do.

Desired output:

enter image description here

Best Answer

Do you want to stack the objects? In this case a version of \atop can do it (using \genfrac, of course). The trick is to force \textstyle when the object is found in \displaystyle, otherwise the standard action is good.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\stk}[2]{\mathinner{\!\mathpalette\stk@{{#1}{#2}}\!}}
\newcommand{\stk@}[2]{%
  \ifx#1\displaystyle
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\genfrac{}{}{0pt}{1}}%
  {\genfrac{}{}{0pt}{}}%
  #2%
}
\makeatother

\begin{document}

\[
A_{z\stk{x}{y}\stk{y}{x}} \qquad
z\stk{x}{y}\stk{y}{x}\ne z_{xy}^{yx} \qquad
z\stk{aa}{b}\stk{b}{aa}
\]

\end{document}

enter image description here

Related Question