我想大多数人都知道,\bar
创建一个太小的条形图,但\overline
创建一个太长的条形图。我最近遇到了这个优秀的答案其中定义了新命令\widebar
,完美地实现了平衡:
现在的问题是,人们可能想要写\widebar{\widebar{A}}
(例如,在写关于集合闭包是幂等的注释时)。然而,当我尝试这样做时,我得到了以下结果:
有什么想法可以让我制作出\widebar
宽度保持不变的双倍尺寸吗?非常感谢您的帮助。
编辑: 我愿意不是希望使用\overline{\overline{...}}
或\bar{\bar{...}}
,因为它们使用一次时的问题仍然存在:即一个太小,另一个太大。我想获得双倍的\widebar
。
答案1
虽然我不完全理解\widebar
您链接到的答案中定义的宏,但我已设法对其进行修改,以适用于其他重音(包括堆叠重音)。
以下是代码:
\documentclass{article}
\usepackage{amsmath}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code is a slight modification of Hendrik Vogt's \widebar %%
%% See: https://tex.stackexchange.com/questions/16337 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
\setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
\setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
\ifdim\ht0=\ht2 #3\else #2\fi
}
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\wideaccent[2]{\@ifnextchar^{{\wide@accent{#1}{#2}{0}}}{\wide@accent{#1}{#2}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@accent[3]{\if@single{#2}{\wide@accent@{#1}{#2}{#3}{1}}{\wide@accent@{#1}{#2}{#3}{2}}}
\newcommand*\wide@accent@[4]{%
\begingroup
\def\mathaccent##1##2{%
%Enable nesting of accents:
\let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
\if#42 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
\setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
\setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
\dimen@\wd\tw@
\advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
\divide\dimen@ 3
\@tempdima\wd\tw@
\advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
\divide\@tempdima 10
\advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
\ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
\rel@kern{0.6}\kern-\dimen@
\if#41
#1{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
\advance\[email protected]\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
\let\final@kern#3%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
#1{\rel@kern{-0.6}\kern\dimen@#2}%
\fi
}%
\macc@depth\@ne
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
\macc@set@skewchar\relax
\let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
\if#41
\macc@nested@a\relax111{#2}%
\else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
\def\gobble@till@marker##1\endmarker{}%
\futurelet\first@char\gobble@till@marker#2\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\doubleoverline[1]{\overline{\overline{#1}}}
\newcommand\widebar{\wideaccent\overline}
\newcommand\widebarbar{\wideaccent\doubleoverline}
\begin{document}
\begin{tabular}{cc}
$\widebar{A \cup B}$
&
$\widebarbar{A \cup B}$
\\
\verb$\widebar{A \cup B}$
&
\verb$\widebarbar{A \cup B}$
\end{tabular}
\end{document}
请注意,这也适用于其他重音组合:
\newcommand\hatoverline[1]{\widehat{\overline{#1}}}
\newcommand\widehatbar{\wideaccent\hatoverline}
\[
\widehat{\widebar{A}} \neq \widehatbar{A}
\]