例如,我想表示一个集合的闭包或扩展实数,$\bar{\mathbb{R}}$
但不幸的是,这会创建一个太小(水平)的条形,几乎看不见。另一方面,$\overline{\mathbb{R}}$
会创建一条太长的线。我需要在条形和上划线之间恰到好处的东西。我的最佳选择是什么?
答案1
这是一个\xoverline[width percent]{symb}
可以执行此操作的命令。请注意,它不会在下标或上标内缩放。如果您需要这样做,则所有内容都必须经过,\mathchoice
从而导致代码更加复杂。
\documentclass{article}
\usepackage{amsmath,amssymb}
\makeatletter
\newsavebox\myboxA
\newsavebox\myboxB
\newlength\mylenA
\newcommand*\xoverline[2][0.75]{%
\sbox{\myboxA}{$\m@th#2$}%
\setbox\myboxB\null% Phantom box
\ht\myboxB=\ht\myboxA%
\dp\myboxB=\dp\myboxA%
\wd\myboxB=#1\wd\myboxA% Scale phantom
\sbox\myboxB{$\m@th\overline{\copy\myboxB}$}% Overlined phantom
\setlength\mylenA{\the\wd\myboxA}% calc width diff
\addtolength\mylenA{-\the\wd\myboxB}%
\ifdim\wd\myboxB<\wd\myboxA%
\rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
\else
\hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%
\fi}
\makeatother
\begin{document}
$|\xoverline{W}|~~
|\xoverline{i}|~~
|\xoverline[3.0]{i}|$
\bigskip
$\bar{\mathbb{R}}~~\overline{\mathbb{R}}~~\xoverline{\mathbb{R}}$
\end{document}
答案2
我通常会定义一个命令,将每边的\overbar
宽度减少。\overline
1.5mu
\documentclass{article}
\usepackage{amsfonts}
\newcommand{\overbar}[1]{\mkern 1.5mu\overline{\mkern-1.5mu#1\mkern-1.5mu}\mkern 1.5mu}
\begin{document}
$\bar{\mathbb{R}}$ $\overbar{\mathbb{R}}$ $\overline{\mathbb{R}}$
\end{document}
答案3
我花了一段时间才找到一个命令,可以将一个 niceoverline
放在任何字段名称上,无论它是实数、有理数、有限域还是单个文字。基于这和那\closure
,我编写了用于\olsi
在参数仅为单个文字时添加上划线的命令,\ols
否则为上划线。下表对这些命令进行了比较。
作为一个小奖励,它也不需要加载任何额外的包。
\documentclass{standalone}
\usepackage{amssymb}
%command for alg-closure that automatically adapts its 'bar' to the arg based on the args length (including '\')
\newcommand{\ols}[1]{\mskip.5\thinmuskip\overline{\mskip-.5\thinmuskip {#1} \mskip-.5\thinmuskip}\mskip.5\thinmuskip} % overline short
\newcommand{\olsi}[1]{\,\overline{\!{#1}}} % overline short italic
\makeatletter
\newcommand\closure[1]{
\tctestifnum{\count@stringtoks{#1}>1} %checks if number of chars in arg > 1 (including '\')
{\ols{#1}} %if arg is longer than just one char, e.g. \mathbb{Q}, \mathbb{F},...
{\olsi{#1}} %if arg is just one char, e.g. K, L,...
}
% FROM TOKCYCLE:
\long\def\count@stringtoks#1{\tc@earg\count@toks{\string#1}}
\long\def\count@toks#1{\the\numexpr-1\count@@toks#1.\tc@endcnt}
\long\def\count@@toks#1#2\tc@endcnt{+1\tc@ifempty{#2}{\relax}{\count@@toks#2\tc@endcnt}}
\def\tc@ifempty#1{\tc@testxifx{\expandafter\relax\detokenize{#1}\relax}}
\long\def\tc@earg#1#2{\expandafter#1\expandafter{#2}}
\long\def\tctestifnum#1{\tctestifcon{\ifnum#1\relax}}
\long\def\tctestifcon#1{#1\expandafter\tc@exfirst\else\expandafter\tc@exsecond\fi}
\long\def\tc@testxifx{\tc@earg\tctestifx}
\long\def\tctestifx#1{\tctestifcon{\ifx#1}}
\long\def\tc@exfirst#1#2{#1}
\long\def\tc@exsecond#1#2{#2}
\makeatother
\begin{document}
\begin{tabular}{r|ccccccc}
\texttt{\textbackslash overline} & $\overline{\mathbb{R}}$ & $\overline{\mathbb{Q}}$ & $\overline{\mathbb{F}_p}$ & $\overline{K}$ & $\overline{L}$ & $\overline{L_1}$ & $\mathcal{Z}_{\overline{K}}$\\
\texttt{\textbackslash bar} & $\bar{\mathbb{R}}$ & $\bar{\mathbb{Q}}$ & $\bar{\mathbb{F}_p}$ & $\bar{K}$ & $\bar{L}$ & $\bar{L_1}$ & $\mathcal{Z}_{\bar{K}}$\\[4pt]
\texttt{\textbackslash ols} & $\ols{\mathbb{R}}$ & $\ols{\mathbb{Q}}$ & $\ols{\mathbb{F}_p}$ & $\ols{K}$ & $\ols{L}$ & $\ols{L_1}$ & $\mathcal{Z}_{\ols{K}}$\\
\texttt{\textbackslash olsi} & $\olsi{\mathbb{R}}$ & $\olsi{\mathbb{Q}}$ & $\olsi{\mathbb{F}_p}$ & $\olsi{K}$ & $\olsi{L}$ & $\olsi{L_1}$ & $\mathcal{Z}_{\olsi{K}}$\\[4pt]
\texttt{\textbackslash closure} & $\closure{\mathbb{R}}$ & $\closure{\mathbb{Q}}$ & $\closure{\mathbb{F}_p}$ & $\closure{K}$ & $\closure{L}$ & $\closure{L_1}$ & $\mathcal{Z}_{\closure{K}}$\\
\end{tabular}
\end{document}
答案4
我不是 Latex 专家,但我编写了一个代码,可让您在另一个答案中控制顶部栏的长度和位置。也许这对某些人有帮助。
查看完整答案查看所有示例和缺点。
以下是摘要:
\mybar{<scale factor>}{<right shift>}{<math expression>}
\usepackage{mathtools} % <----- for '\mathrlap' command (necessary)
\newcommand{\mybar}[3]{%
\mathrlap{\hspace{#2}\overline{\scalebox{#1}[1]{\phantom{\ensuremath{#3}}}}}\ensuremath{#3}
}
使用示例:
$\mybar{0.6}{3pt}{A}$
如果您打算针对特定的数学表达式更频繁地使用此命令,则可以使用以下代码使内容更简洁。
\mybar[<scale factor>][<right shift>]{<math expression>}
\usepackage{mathtools} % <----- for '\mathrlap' command (necessary)
\usepackage{xparse} % <----- for '\NewDocumentCommand' command (necessary)
\NewDocumentCommand{\mybar}{ O{0.60} O{3pt} m }{% <---- Set the default values here
\mathrlap{\hspace{#2}\overline{\scalebox{#1}[1]{\phantom{\ensuremath{#3}}}}}\ensuremath{#3}
}
使用示例:
$\mybar{A}$
$\mybar{V}$ % <---- bad result
$\mybar[0.6][2pt]{V}$ % <---- set manually