我想写一个顶部有横线的 X。X 应该是直立的,但在标题中应该是斜体。横线应该在正确的位置。所以我的问题是将 \overline 对齐为“斜体”字体我开始玩jfbu 的解决方案但无法使原始的 upshape 位置发挥作用。
\documentclass{article}
\usepackage{xspace}
\newbox\usefulbox
\makeatletter
\def\getslant #1{\strip@pt\fontdimen1 #1}
\def\skoverline #1{\mathchoice
{{\setbox\usefulbox=\hbox{$\m@th\displaystyle #1$}%
\dimen@ \getslant\the\textfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\textstyle #1$}%
\dimen@ \getslant\the\textfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\scriptstyle #1$}%
\dimen@ \getslant\the\scriptfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\scriptscriptstyle #1$}%
\dimen@ \getslant\the\scriptscriptfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}%
{}}
\makeatother
\newcommand{\xbar}{$\skoverline{X}$\xspace}
\newcommand{\xbarup}{\mbox{$\overline{\mbox{X}}$}\xspace}
\newcommand{\xbarupsk}{\mbox{$\skoverline{\mbox{X}}$}\xspace}
\begin{document}\thispagestyle{empty}
\xbar-Theory
\emph{\xbar-Theory} (correct)
\xbarup-Theory (correct)
\emph{\xbarup-Theory}
\xbarupsk-Theory
\emph{\xbarupsk-Theory}
\end{document}