在数学模式下,倾斜的字符看起来与\overline
: 有点脱节$\overline{P}$
,看起来很奇怪;当然,我希望条形图更靠右对齐,至少倾斜程度与字母顶部一样。如何实现这一点?
答案1
以下内容摘自聊天中最近的讨论。
为了最多情况下,以下修改后的\overline
名为的定义\myol
有效:
\newcommand{\myol}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
默认调整为\overline
(3mu
点击图像放大以获取更多细节):
\documentclass{article}
\newcommand{\myol}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
\begin{document}
\[\begin{array}{c}
\overline{A}\ \overline{B}\ \overline{C}\ \overline{D} \overline{E}\ \overline{F}\ \overline{G}\ \overline{H} \overline{I}\ \overline{J}\ \overline{K}\ \overline{L} \overline{M}\ \overline{N}\ \overline{O}\ \overline{P} \overline{Q}\ \overline{R}\ \overline{S}\ \overline{T} \overline{U}\ \overline{V}\ \overline{W}\ \overline{X} \overline{Y}\ \overline{Z}\\[\jot]
\myol{A}\ \myol{B}\ \myol{C}\ \myol{D} \myol{E}\ \myol{F}\ \myol{G}\ \myol{H} \myol{I}\ \myol{J}\ \myol{K}\ \myol{L} \myol{M}\ \myol{N}\ \myol{O}\ \myol{P} \myol{Q}\ \myol{R}\ \myol{S}\ \myol[1]{T} \myol{U}\ \myol[1]{V}\ \myol[1]{W}\ \myol{X} \myol[1]{Y}\ \myol{Z}
\end{array}\]
\end{document}
请注意,\myol
对于上重下窄的字母(如上例中的 、 和 ),T
需要V
进行W
一些调整。Y
答案2
这是一个自动宏。它受到 TeXBook 第 375 页的启发,并来自\skew
LaTeX2e 内核的定义。我很讨厌进入和退出数学模式,但这样,宏\skoverline
就可以将一些更通用的材料与其参数中的字母混合在一起。
\documentclass{article}
\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
\begin{document}\thispagestyle{empty}
$\overline{P}$
$\skoverline{P}$
$x^{\overline{M}}$
$x^{\skoverline{M}}$
$\overline{SPQR}$
$\skoverline{SPQR}$
\end{document}
代码被盗沃纳的回答:
\[\begin{array}{c}
\overline{A}\ \overline{B}\ \overline{C}\ \overline{D} \overline{E}\ \overline{F}\ \overline{G}\ \overline{H} \overline{I}\ \overline{J}\ \overline{K}\ \overline{L} \overline{M}\ \overline{N}\ \overline{O}\ \overline{P} \overline{Q}\ \overline{R}\ \overline{S}\ \overline{T} \overline{U}\ \overline{V}\ \overline{W}\ \overline{X} \overline{Y}\ \overline{Z}\\[\jot]
\skoverline{A}\ \skoverline{B}\ \skoverline{C}\ \skoverline{D} \skoverline{E}\ \skoverline{F}\ \skoverline{G}\ \skoverline{H} \skoverline{I}\ \skoverline{J}\ \skoverline{K}\ \skoverline{L} \skoverline{M}\ \skoverline{N}\ \skoverline{O}\ \skoverline{P} \skoverline{Q}\ \skoverline{R}\ \skoverline{S}\ \skoverline{T} \skoverline{U}\ \skoverline{V}\ \skoverline{W}\ \skoverline{X} \skoverline{Y}\ \skoverline{Z}
\end{array}\]
答案3
我非常喜欢 user4686 对 skoverline 的定义,但我发现 LaTeX2e 代码有点难以阅读/理解/修改。因此,我尝试将代码移植到 LaTeX3。据我所知,以下代码应该产生完全相同的结果(即上划线的字距为当前字体倾斜“宽度”的一半)。
% -- skoverline (ported from https://tex.stackexchange.com/a/95079/114489 CC-BY-SA 3.0) --
% Gets the slant per pt of the height of a character in a given font.
% Returns a dimensionless value which can be multiplied with a height in pt.
\cs_new:Nn \__skoverline_get_slant_per_pt_of_height:n { \dim_to_decimal:n { \fontdimen1 #1 } }
% Typesets an overline kerned by a given amount for a given box.
%
% Usage: \__skoverline_kerned_overline:NN <kern dim> <content box>
\cs_new:Nn \__skoverline_kerned_overline:NN
{
% Start drawing overline after half the slant width.
\kern #1
\overline
{
% Move back half the slant width.
\kern -#1
% Insert the box containing the content.
\box_use_drop:N #2
% Move half the slant width forward again.
\kern #1
}
% Move half the slant width back once more, after finishing the overline.
\kern -#1
}
\NewDocumentCommand \skoverline { m }
{
\mathchoice
{{ % display style math
% Typeset #1 in hbox and store in variable for measuring and later use.
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \displaystyle #1$ }
% Get the slant width for the hbox's height.
% (note: in a dimension expression, writing values next to each other is multiplication)
%
% |←→|____
% | / /
% | / /
% |/___/
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \textfont\symletters }
\box_ht:N \l_tmpa_box
}
% Use only half the slant width.
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
% This results in the overline being above the slanted character's
% horizontal at half it's height.
%
% |←-→|
% ____
% / /
% / /
% /___/
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % text style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \textstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \textfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % script style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \scriptstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \scriptfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % script script style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \scriptscriptstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \scriptscriptfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
}
为了证明它仍然以这种方式工作,以下是来自https://tex.stackexchange.com/a/95084/4686使用此实现进行排版(使用独立类、fontspec 和 unicode-math):
注意:我还没有编写 LaTeX 宏的经验,这些宏实际上可以“手动”排版,而且我对 LaTeX2e 宏的理解也有限。如果有 LaTeX 专家能给我一些提示或更正,我将不胜感激。^^