
基本上,我想要這樣的東西:
$$ \overset{\qquad\quad\; 2}{\sqrt{x+x^2}} $$
上面的表達式(自動)右對齊,但我不知道如何實現這一點。 (上面的例子是手動間隔的,我希望它是自動的。)
答案1
使用\hfill
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\overset{\hfill 2}{\sqrt{x+x^2}}
\]
\end{document}
在現代 LaTeX 文件中,您不應使用 TeX 結構$$...$$
,而應使用\[...\]
.看為什麼 \[ ... \] 優於 $$ ... $$?。
答案2
使用堆疊,您可以獲得兩個正確\scriptstyle
數字的對齊方式,這就是我閱讀OP問題的方式。也許這是比OP要求的更具限制性的解釋(貢薩洛以稍微不同的方式解釋“對齊”)。
\documentclass{article}
\usepackage{stackengine}
\begin{document}
\def\sqrtoverset#1#2{\ensurestackMath{%
\def\stackalignment{r}\def\stacktype{L}\stackon[0pt]{%
\def\stacktype{S}\stackon[1pt]{#1}{{}^{#2}}%
}{\displaystyle\sqrt{\phantom{#1}}}%
}}
\[
\sqrtoverset{x+x^2}{2}
\]
\end{document}