[Tex/LaTex] How to keep a nice layout when combining overline/underline with superscript/subscript

heightsubscriptssuperscriptsunderline

I would like to add indices as subscripts and superscripts to a couple of bounds denoted by underline (lower bound) and overline (upper bound), but I am not able to keep the same well-shaped look of the overall symbol, since the superscript is raised and the subscript is lowered with respect to the symbol not underlined/overlined (so that the resulting formula exceeds the textstyle space).
Am I doing something wrong?

PS: The same problem affects only the subscript when used together with a superscript:

\[ \theta_k \; \underline \theta_k \]
\[ \theta^{\delta} \; \overline \theta^{\delta} \]
\[ \theta_k \;  \theta^{\delta} \; \theta_k^{\delta}\]

enter image description here

Best Answer

This still doesn't take care of line 3 (combined sub/superscript), but it does remedy the under/overline issue. I personally do not find the line 3 issue objectionable.

\documentclass{article} 
\newcommand\utheta{\vphantom{theta}\smash{\underline \theta}}
\newcommand\otheta{\vphantom{theta}\smash{\overline \theta}}
\begin{document}
\[ \theta_k \; \utheta_k \]
\[ \theta^{\delta} \; \otheta^{\delta} \]
\[ \theta_k \;  \theta^{\delta} \; \theta_k^{\delta}\]
\end{document}

enter image description here

Related Question