Center superscript relative to subscript in math mode

Set them in equivalently-sized boxes. This is easily supported using \eqmakebox[<tag>][<align>]{<stuff>}; this sets <stuff> in a box of maximum width across all <tag>s (with a conditional <align>ment: left, centre (default) or right-aligned):

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}

\begin{document}

This is an example of how the command would be used: 
\[
  \text{M}
    ^{\eqmakebox[aaa]{$\scriptstyle a,\dots,a$}}
    _{\eqmakebox[aaa]{$\scriptstyle a,a,\dots,a,a$}}
  \text{M}
\]

\end{document}

Compile at least twice with the change of maximum width in any <tag>ged \eqmakebox.


You can absorb the subscripts and superscripts, measure them and then apply them.

\documentclass{report}
\usepackage{amsmath,xparse}

\makeatletter
\newsavebox{\supsub@sup}
\newsavebox{\supsub@sub}
\newlength{\supsub@wd}

\NewDocumentCommand{\supsub}{me{^_}}{%
  \sbox\supsub@sup{$\m@th\scriptstyle\IfValueT{#2}{#2}$}%
  \sbox\supsub@sub{$\m@th\scriptstyle\IfValueT{#3}{#3}$}%
  \setlength{\supsub@wd}{\wd\supsub@sup}%
  \ifdim\supsub@wd<\wd\supsub@sub
    \setlength{\supsub@wd}{\wd\supsub@sub}%
  \fi
  #1%
  \IfValueT{#2}{^{\makebox[\supsub@wd]{\usebox{\supsub@sup}}}}%
  \IfValueT{#3}{_{\makebox[\supsub@wd]{\usebox{\supsub@sub}}}}%
}
\makeatother

\begin{document}

This is an example of how the command would be used: 
\begin{equation*}
\supsub{\mathrm{M}}^{a,\dots,a}_{a,a,\dots,a,a} \mathrm{M}
\end{equation*}

\end{document}

enter image description here

If you prefer a different syntax:

\documentclass{report}
\usepackage{amsmath}

\makeatletter
\newsavebox{\supsub@sup}
\newsavebox{\supsub@sub}
\newlength{\supsub@wd}

\newcommand{\supsub}[2]{%
  \sbox\supsub@sup{$\m@th\scriptstyle#1$}%
  \sbox\supsub@sub{$\m@th\scriptstyle#2$}%
  \setlength{\supsub@wd}{\wd\supsub@sup}%
  \ifdim\supsub@wd<\wd\supsub@sub
    \setlength{\supsub@wd}{\wd\supsub@sub}%
  \fi
  ^{\makebox[\supsub@wd]{\usebox{\supsub@sup}}}%
  _{\makebox[\supsub@wd]{\usebox{\supsub@sub}}}%
}
\makeatother

\begin{document}

This is an example of how the command would be used: 
\begin{equation*}
\mathrm{M}\supsub{a,\dots,a}{a,a,\dots,a,a} \mathrm{M}
\end{equation*}

\end{document}

Note that \text{M} is incorrect: if you want to be sure that "M” is upright, use \mathrm{M}. Also a blank line before a math display environment is wrong.