对于数学和文本模式,垂直居中内联文本的最佳方法是什么?
有没有类似\textsuperscript
非数学模式的东西?
答案1
这是一个很好的机会来说明 Victor Eijkhout 编写的宏,该宏可以在 TeX by Topic 第 12.6.8 节中找到;与直接使用相比,它的优势在于\vcenter
它\setbox<number>=\xvcenter{...}
是可能的。
宏\midscript
在(第一级)下标或上标中选择较小的尺寸。它在第二级中不会产生好的结果。
\documentclass{article}
% macro by V. Eijkhout in TeX by Topic
\makeatletter
\protected\def\xvcenter{%
\hbox\bgroup$\everyvbox{\everyvbox{}\aftergroup\m@th\aftergroup$\aftergroup\egroup}%
\vcenter
}
% The \everyvbox token list will be executed
% just after the { that follows \vcenter;
% the closing } will trigger the three \aftergroup tokens
% so $ will balance the formula started in the outer \hbox
% and \egroup will close it.
% I added to Eijkhout's macro also \m@th to neutralize the
% \mathsurround and \protected, just to be on the safe side.
\DeclareRobustCommand{\midscript}[1]{
\mathchoice{\mid@script\scriptstyle{#1}}
{\mid@script\scriptstyle{#1}}
{\mid@script\scriptscriptstyle{#1}}
{\mid@script\scriptscriptstyle{#1}}
}
\newcommand{\mid@script}[2]{
\vcenter{\hbox{$\m@th#1#2$}}
}
\DeclareRobustCommand{\textmidscript}[1]{%
\xvcenter{\hbox{\scriptsize#1}}%
}
\makeatletter
\begin{document}
$x^{a}$ $x_{a}$ $x\midscript{a}-$ $x^{x\midscript{a}-}$
x\textsuperscript{a} x\textsubscript{a} x\textmidscript{a}
\end{document}
答案2
也许是这样的?(第一行末尾的尾随一元减号只是为了证明“中间字母”与数学中心线对齐。)
\documentclass{article}
\newcommand\mathmiddlescript[1]{\vcenter{\hbox{$\scriptstyle #1$}}}
\newcommand\textmiddlescript[1]{$\vcenter{\hbox{\scriptsize #1}}$}
\begin{document}
$x^{a}$ $x_{a}$ $x\mathmiddlescript{a}-$
x\textsuperscript{a} x\textsubscript{a} x\textmiddlescript{a}
\end{document}