
是否可以修改符號的下標和上標的水平對齊方式?也就是說是否可以得到這對右對齊的下標/上標
而不是這對左對齊的下標/上標
當我有這樣的程式碼:
\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
$x_{101}^{1}$
\end{document}
筆記:我是不是尋找一個手動的解決方案(例如,hphantom
我用來創建上面的範例),而是一個真正的自動化一擊通的解決方案。
編輯:我對不修補現有子/上標機制的解決方案感到滿意(儘管我很好奇這是否可能)。該解決方案還可以使用自訂命令,即\foo{x}{101}{1}
只要它遵守正確的數學模式子/上標間距等。
答案1
我不確定這樣做的目的是什麼,但它是:
\documentclass{article}
\usepackage{mathtools}
\DeclareRobustCommand{\subsup}[3]{{%
\mathpalette\makesubsup{{#1}{#2}{#3}}%
}}
\makeatletter
\providecommand{\@firstofthree}[3]{#1}
\providecommand{\@secondofthree}[3]{#2}
\providecommand{\@thirdofthree}[3]{#3}
\newcommand{\makesubsup}[2]{%
\sbox\z@{$\m@th#1{}_{\@secondofthree#2}$}%
\sbox\tw@{$\m@th#1{}^{\@thirdofthree#2}$}%
\dimen@=\wd\z@
\ifdim\wd\tw@>\wd\z@ \dimen@=\wd\tw@\fi
{\mkern0mu \@firstofthree#2}%
_{\mathmakebox[\dimen@][r]{\@secondofthree#2}}%
^{\mathmakebox[\dimen@][r]{\@thirdofthree#2}}%
}
\makeatother
\begin{document}
$\subsup{x}{101}{1}-\subsup{y}{1}{101}$
$A_{\subsup{x}{101}{1}}$
\end{document}
只需測量下標和上標,然後將方框製作得與較大的方框一樣寬。請注意,這也適用於二級子/上標。
答案2
這是一個開始,與\Ss{}{}{}
.也經過編輯以處理顯示樣式的內容。編輯後也可以自動使用下標樣式。修正瞭如果上標長度超過下標長度則巨集無法正常運作的明顯錯誤。
\documentclass{article}
\usepackage{amsmath,stackengine,scalerel}
\newcommand\Ss[3]{\setbox0=\hbox{$#2$}\setbox2=\hbox{$#3$}\ifdim\wd2<\wd0%
\ThisStyle{\ensurestackMath{\stackengine%
{0pt}{\SavedStyle#1_{#2}^{}}{\SavedStyle{\phantom{#1}}^{#3}}{O}{r}{F}{F}{L}}}%
\else
\ThisStyle{\ensurestackMath{\stackengine%
{0pt}{\SavedStyle{\phantom{#1}}_{#2}^{}}{\SavedStyle#1^{#3}}{O}{r}{F}{F}{L}}}%
\fi
}
\begin{document}
\parskip 4pt\centering
$x_{101}^{1}$
$\Ss{x}{101}{1}$
$X_{101}^{1}$
$\Ss{X}{101}{1}$
$(A)_{123}^{ijklm}$
$\Ss{(A)}{123}{ijklm}$
\[
\biggl(\frac{1}{2}\biggr)_{123}^{4}\quad
\Ss{\biggl(\frac{1}{2}\biggr)}{123}{4}
\]
$A_{\Ss{x}{101}{1}}$
\end{document}
答案3
例如,您可以嘗試以下操作:
\def\sf#1_#2^#3{%
\setbox1=\hbox{$\scriptstyle#2$}%
\setbox2=\hbox{$\scriptstyle#3$}%
\ifdim\wd2>\wd1 \dimen0=\wd2 \else \dimen0=\wd1 \fi
\setbox2=\hbox to\dimen0{\hss\box2}%
\setbox1=\hbox to\dimen0{\hss\box1}%
#1_{\box1}^{\box2}
}
$\sf x_{100}^{2}$
\bye