# How to center an index or variable under an expression or word in math-mode

How can I get the the term shown in the picture:

$\underline{x_a}$ should be centered under max.

What I know is the structure below, but this is not what I am looking for:

$max_{\atop \underline{x_a}}^k$


If \underline is really needed this is a matter of taste (I just kept it)

But the centering can be achieved by using \underset. \max is declared as an operator, as far as I know.

\documentclass{article}

\usepackage{mathtools}

\begin{document}
$\underset{\underline{x_{a}}}{\max}^k$
\end{document}


• Dear complainers (and there will be some again): It's not my style about \underline...
– user31729
Jan 24, 2016 at 11:07
• What is wrong about \underline ? Jan 24, 2016 at 11:09
• @kimliv: \underline is actually not wrong, rather underlining that really look nice in general
– user31729
Jan 24, 2016 at 11:21
• in this case \underline is necessary since x is a vector of a boolean variable. Jan 24, 2016 at 11:34

If you want to keep the standard notation for \max, you can play some tricks:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\varmax}[1]{%
\mathop{}\!{\mathpalette\varmaxback{#1}}\!%
\mathop{\hphantom{{}^{#1}}\!\max\nolimits^{#1}}\limits
}

\newcommand{\varmaxback}[2]{%
\sbox0{\mathsurround=0pt $#1{}^{#2}$}%
\kern-\wd0
}

\begin{document}
$\varmax{k}_{\underline{x_a}}$
\begin{align*}
X&=\varmax{k}_{\underline{x_a}}=Y
\\
X&=\max_{\underline{x_a}}
\end{align*}
\end{document}